36 Commits

Author SHA1 Message Date
Alex Bradbury
83f065d582 [RISCV] static_assert SupportedProfiles and SupportedExperimentalProfiles are sorted
Just as we do for the arrays of extension names.
2024-05-15 21:34:07 +01:00
Alex Bradbury
891d687137
[RISCV] Gate unratified profiles behind -menable-experimental-extensions (#92167)
As discussed in the last sync-up call, because these profiles are not
yet finalised they shouldn't be exposed to users unless they opt-in to
them (much like experimental extensions). We may later want to add a
more specific flag, but reusing `-menable-experimental-extensions`
solves the immediate problem.

This is implemented using the new support for marking profiles s
experimental added in #91993 to move the unratified profiles to
RISCVExperimentalProfile and making the necessary changes to logic in
RISCVISAInfo to handle this.
2024-05-15 21:09:43 +01:00
VincentWu
844355a8cb
[RISC-V] remove I ext when E ext has been enabled (#92070)
After patch https://github.com/llvm/llvm-project/pull/88805

`I` Ext will be added automatically when we running the command like 
`./build/bin/llc -mtriple=riscv32 -mattr=+e -target-abi ilp32e
-verify-machineinstrs llvm/test/CodeGen/RISCV/zcmp-additional-stack.ll`

it will generate 
```
	.text
	.attribute	4, 16
	.attribute	5, "rv32i2p1_e2pe"
	.file	"zcmp-additional-stack.ll"
	.globl	func                            # -- Begin function func
	.p2align	1
	.type	func,@function
```

This patch reset the I ext in FeatureBit when `+e` has been specify
2024-05-15 08:26:45 +10:00
Craig Topper
30aa49cbc2 [RISCV] Remove the pre-split from RISCVISAInfo::parseArchString. NFCI
We can extract each extension as we process them without much
complexity.
2024-05-10 15:31:44 -07:00
Craig Topper
7237bef5da [RISCV] Use map::count instead of hasExtension in computeDefaultABI. NFC
hasExtension checks if the extension name is a known extension name.
That should always be true for the extensions listed here so we can
skip that check.
2024-05-10 12:20:24 -07:00
Craig Topper
d8f8ac8f5f
[RISCV] Don't pre-split before the loop in parseNormalizedArchString. (#91684)
We can extract each extension as we process them without much
complexity.

I changed the error message for cases where there are double underscores
or a trailing underscore. I think this is an improvement over the
previous error.
2024-05-10 08:59:56 -07:00
Craig Topper
e069bb7fd8 [RISCV] Use map::count instead of hasExtension in RISCVISAInfo::updateCombination. NFC
hasExtension check isSupportedExtension before the map lookup. All
of the extensions we check for in updateCombination should be valid
extension names so we can bypass that to save some time.
2024-05-09 20:14:44 -07:00
Craig Topper
1aaab334c5
[RISCV] Don't use std::vector<std::string> for split extensions in RISCVISAInfo::parseArchString. NFC (#91538)
We can use a SmallVector<StringRef>.

Adjust the code so we check for empty strings in the loop instead of
making a copy of the vector returned from StringRef::split.

This overlaps with #91532 which also removed the std::vector, but
that PR may be more controversial.
2024-05-08 17:22:18 -07:00
Craig Topper
2c20995781
[RISCV] Detect duplicate extensions in parseNormalizedArchString. (#91416)
This detects the same extension name being added twice. Mostly I'm
worried about the case that the same string appears with two different
versions. We will only preserve one of the versions.

We could allow the same version to be repeated, but that doesn't seem
useful at the moment.

I've updated addExtension to use map::emplace instead of
map::operator[]. This means we only keep the first version if there are
duplicates. Previously we kept the last version, but that shouldn't matter
now that we don't allow duplicates. parseArchString already doesn't allow
duplicates.
2024-05-07 20:56:55 -07:00
Craig Topper
6cba93f25d [RISCV] Add partial validation of S and X extension names to RISCVISAInfo::parseNormalizedArchString.
Extensions starting with 's' or 'x' should always be followed by an
alphabetical character.  I don't know of any crashes from this currently,
but it seemed better to be defensive.
2024-05-07 12:16:55 -07:00
Craig Topper
0faf494200
[RISCV] Make parseArchString only accept [a-z0-9_]. (#90879)
Similar change was recently made to parseNormalizedArchString.
2024-05-03 09:29:27 -07:00
Craig Topper
7a6847e001
[RISCV] Add partial validation of Z extension name to RISCVISAInfo::parseNormalizedArchString (#90895)
If 'z' is given as the complete extension name or with a digit after it,
it will crash in the extension map compare function. Check for these
cases and give an error.
2024-05-03 09:29:11 -07:00
Craig Topper
5445a35d6e
[RISCV] Detect empty extension name after parsing MajorVersion in parseNormalizedArchString. (#90790)
If the string is just a version, we will end up adding an empty string
as an extension which crashes in the compare function for the std::map.
2024-05-02 10:08:35 -07:00
Craig Topper
941eab102f
[RISCV] Make parseNormalizedArchString only accept [a-z0-9_]. (#90815)
Previously we only rejected upper case characters. We should instead
reject anything except lower case, numbers, and underscore. Other
characters will likely confuse the extension sorting.
2024-05-02 09:39:52 -07:00
Craig Topper
ab8ac36f10
[RISCV] Add list of supported profiles to -print-supported-extensions (#90757)
I tried also printing the -march they correspond to, but it seemed
overly verbose and caused line wraps. It might be better if we remove
the versions numbers from the string or did a more intelligent line
wrap.
2024-05-02 08:18:02 -07:00
Craig Topper
500dda049e [RISCV] Refactor version major version parsing in parseNormalizedArchString. NFC
Use an index variable and array indexing instead of manipulating
a temporary StringRef.
2024-05-01 14:56:56 -07:00
Craig Topper
a7e0798854
[RISCV] Use binary search to look up supported profiles. (#90767)
As the list of profiles grow, this will be a more efficient lookup.

Because the profile name is a prefix of the Arch string, we use
upper_bound to find the first profile that definitely comes after the
Arch string. If that isn't the first supported profile, we move back 1
profile and see if that profile is a prefix of our Arch string.
2024-05-01 14:56:14 -07:00
Craig Topper
cf3c714e4b
[RISCV] Merge RISCVISAInfo::updateFLen/MinVLen/MaxELen into a single function. (#90665)
This simplifies the callers.
2024-05-01 10:44:10 -07:00
Craig Topper
09f4b06dde
[RISCV] Refactor profile selection in RISCVISAInfo::parseArchString. (#90700)
Instead of hardcoding the 4 current profile prefixes, treat profile
selection as a fallback if we don't find "rv32" or "rv64".

Update the error message accordingly.
2024-05-01 10:39:24 -07:00
Craig Topper
05d04f0a05
[RISCV] Make RISCVISAInfo::updateMaxELen extension checking more robust. Add inference from V extension. (#90650)
We weren't fully checking that we parsed Zve*x/f/d correctly. This could
break if new extension is added that starts with Zve.

We were assuming the Zve64d is present whenever V is so we only
inferred from Zve*. It's more correct to infer ELEN from V itself too.
2024-04-30 13:49:05 -07:00
Craig Topper
f0cc373521 [RISCV] Drop unnecessary curly braces in RISCVISAInfo:parse*ArchString. NFC 2024-04-30 10:35:45 -07:00
Craig Topper
1b942ae384
[RISCV] Use consume_front to parse rv32/rv64 in RISCVISAInfo::parse*ArchString. NFC (#90562)
This replaces some starts_with calls wth consume_front. This allows us
to remove a later assumption that prefix was 4 characters. We would
eventually need to fix this anyway if we ever support rv128.

Noticed while reviewing the RISCVISAInfo code for other reasons.
2024-04-30 08:13:23 -07:00
Craig Topper
6e83058138 [RISCV] Use an assert insead of a if/else+llvm_unreachable. NFC 2024-04-29 22:49:46 -07:00
Craig Topper
326667d727 [RISCV] Merge variable declaration with first assignment. NFC 2024-04-29 21:59:35 -07:00
David Spickett
6f02120ac4
[llvm][RISCV] Improve error message for invalid extension letters (#90468)
Previously you got:
clang: error: invalid arch name 'rv64v', first letter should be 'e', 'i'
or 'g'

Which to me, unfamiliar with riscv, reads as if I should have used
"[eig]rv64v". Which is not what clang means.

Include the first bit in the error message to make this clearer:
clang: error: invalid arch name 'rv64v', first letter after 'rv64'
should be 'e', 'i' or 'g'
2024-04-29 16:51:09 +01:00
Pengcheng Wang
c705c68476
[RISCV] Generate profiles from RISCVProfiles.td
So we can only mantain one place.

Reviewers: preames, yetingk, topperc

Reviewed By: topperc

Pull Request: https://github.com/llvm/llvm-project/pull/90187
2024-04-28 11:52:36 +08:00
Craig Topper
de375fbc71 [RISCV] Move OrderedExtensionMap typedef to RISCVISAUtils.h. NFC 2024-04-26 17:57:51 -07:00
Craig Topper
451e853e51
[RISCV] Flatten the ImpliedExts table in RISCVISAInfo.cpp (#89975)
Previously we had an individiaul global array of implied extensions for
each extension that needed it. This allowed each array to have a
different length. Then we had a sorted table that stored pointers and
size for the indivual arrays keyed by the extension name.

This patch changes the sorted table to use multiple rows if multiple
extensions are implied. We use equal_range instead of lower_bound to
find all the rows that apply to a given extension.

The CombineIntoExts array was also modified to store only the extension
name that need to be combined. This extension name is looked up in the
implied table to find all the extensions it depends on.
2024-04-26 10:32:21 -07:00
Craig Topper
80628ee0d5
[RISCV] Generate RISCVISAInfo table from RISCVFeatures.td. (#89955)
This generates the SupportedExtensions and ImpliedExts information from
the RISCVExtension records found in RISCVFeatures.td.

Some of the extensions listed in the individual `ImpliedExts*` arrays
may be in a different, but the order in those array doesn't matter. I
manually verified the all the extensions were still present in each
array.

I've added the new information to the existing RISCVTargetParserDef.inc
and RISCVTargetDefEmitter.cpp so we don't need to re-parse the entirety
of RISCV.td a second time for a new file.
2024-04-25 07:07:33 -07:00
Craig Topper
f489043826 [RISCV] Sort the ImpliedExts tables in RISCVISAInfo.cpp alphabetically. NFC 2024-04-24 08:41:23 -07:00
Craig Topper
d9715c698c [RISCV] Don't make Zacas or Zabha imply A in RISCVISAInfo.cpp
Zabha and Zacas are both documented as depending on Zaamo. I'm
hesitant to make them imply Zaamo instead.

So remove the implication and replace with a check that either
A or Zaamo is enabled.
2024-04-23 21:34:04 -07: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
wangpc
c570287fbf [RISCV][NFC] Move RISCVISAInfo back to Support
So that there is no cyclic dependency if we want to use it in
tablegen.

Reviewed By: fpetrogalli

Differential Revision: https://reviews.llvm.org/D140529
2023-01-03 13:55:39 +08:00
Yeting Kuo
bd9c0f082b [RISCV] Add Svpbmt extension support.
Spec of Svpbmt: https://github.com/riscv/riscv-isa-manual/blob/master/src/supervisor.tex#L2399

Reviewed By: kito-cheng

Differential Revision: https://reviews.llvm.org/D140692
2022-12-28 23:57:54 -08:00
Jojo R
54752f3ff6 [RISCV] Implement assembler support for XTHeadVdot
This patch implements the T-Head vendor extensions (XTHeadVdot),
which is documented here, it's based on standard vector extension v1.0:
  https://github.com/T-head-Semi/thead-extension-spec
2022-12-26 19:05:22 +08:00
Archibald Elliott
f09cf34d00 [Support] Move TargetParsers to new component
This is a fairly large changeset, but it can be broken into a few
pieces:
- `llvm/Support/*TargetParser*` are all moved from the LLVM Support
  component into a new LLVM Component called "TargetParser". This
  potentially enables using tablegen to maintain this information, as
  is shown in https://reviews.llvm.org/D137517. This cannot currently
  be done, as llvm-tblgen relies on LLVM's Support component.
- This also moves two files from Support which use and depend on
  information in the TargetParser:
  - `llvm/Support/Host.{h,cpp}` which contains functions for inspecting
    the current Host machine for info about it, primarily to support
    getting the host triple, but also for `-mcpu=native` support in e.g.
    Clang. This is fairly tightly intertwined with the information in
    `X86TargetParser.h`, so keeping them in the same component makes
    sense.
  - `llvm/ADT/Triple.h` and `llvm/Support/Triple.cpp`, which contains
    the target triple parser and representation. This is very intertwined
    with the Arm target parser, because the arm architecture version
    appears in canonical triples on arm platforms.
- I moved the relevant unittests to their own directory.

And so, we end up with a single component that has all the information
about the following, which to me seems like a unified component:
- Triples that LLVM Knows about
- Architecture names and CPUs that LLVM knows about
- CPU detection logic for LLVM

Given this, I have also moved `RISCVISAInfo.h` into this component, as
it seems to me to be part of that same set of functionality.

If you get link errors in your components after this patch, you likely
need to add TargetParser into LLVM_LINK_COMPONENTS in CMake.

Differential Revision: https://reviews.llvm.org/D137838
2022-12-20 11:05:50 +00:00