Skip to content

Add RISC-V Profiles format #36

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 12, 2025
Merged

Add RISC-V Profiles format #36

merged 2 commits into from
May 12, 2025

Conversation

pz9115
Copy link
Contributor

@pz9115 pz9115 commented May 2, 2023

This is a subset work form #26.
Add RISC-V Profiles format only. The doc record in:
https://docs.google.com/document/d/1TZXRIgVfQHWQ6xrZflHXUCSav6xNmliojrW2bEsvPno/edit.

@pz9115 pz9115 requested review from asb and kito-cheng June 29, 2023 04:47
@preames
Copy link
Contributor

preames commented Jul 17, 2023

This got briefly brought up during the SIG toolchain meeting today, but got rapidly derailed into a process discussion. Since the root point seems important, I am repeating it here.

In addition to defining the syntax for the -march string for profiles, there is a separate set of task items required to define and implement support for each of the new extensions which were defined in the ratified profile document.

From the perspective of LLVM, my current intent is to make the support for all the various extensions a blocker for merging the -march profile parsing support. This may evolve, and I'm open to the arguments on why we should adopt a different posture, but that argument will need to be explicitly made.

@pz9115
Copy link
Contributor Author

pz9115 commented Jul 17, 2023

This got briefly brought up during the SIG toolchain meeting today, but got rapidly derailed into a process discussion. Since the root point seems important, I am repeating it here.

In addition to defining the syntax for the -march string for profiles, there is a separate set of task items required to define and implement support for each of the new extensions which were defined in the ratified profile document.

From the perspective of LLVM, my current intent is to make the support for all the various extensions a blocker for merging the -march profile parsing support. This may evolve, and I'm open to the arguments on why we should adopt a different posture, but that argument will need to be explicitly made.

You are right, Christoph added a comment here riscv-admin/dev-partners#16 (comment). In fact, we need to nothing until those new extensions are actually ratified(more details are needed in extenisons specification to approach). So I think maybe is a good idea that only implements the new extensions' names in toolchain Profiles support.

@pz9115 pz9115 requested a review from topperc July 18, 2023 07:11
README.mkd Outdated
Comment on lines 92 to 95
To distinguish between ordinary extension input and input with profiles,
profiles are assumed to be entered `at the beginning of the -march option`, and
then input other extensions. Profiles `should use uppercase letters` in the `-march`
option.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incorrect placement of code (backtick) markup?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm trying to emphasize here the rules for using, do you have any good solutions?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
To distinguish between ordinary extension input and input with profiles,
profiles are assumed to be entered `at the beginning of the -march option`, and
then input other extensions. Profiles `should use uppercase letters` in the `-march`
option.
To distinguish between ordinary extension input and input with profiles,
profiles are assumed to be entered `at the beginning of the -march option`, and
then input other extensions. Profiles *should use uppercase letters* in the `-march`
option.

@pz9115 pz9115 requested a review from TommyMurphyTM1234 July 19, 2023 08:25
@cmuellner
Copy link
Collaborator

The status of the profiles support was briefly discussed in today's SIG toolchain call:

  • this was discussed at the GNU Cauldron with Kito and Palmer (I did not attend, therefore I can't say exactly what was discussed there)
  • patches are expected to get on the list this month (October 2023)

@cmuellner
Copy link
Collaborator

An initial patch was sent to the GCC mailing list today: https://gcc.gnu.org/pipermail/gcc-patches/2023-November/637490.html

@jrtc27
Copy link

jrtc27 commented Nov 21, 2023

Uppercase strings being required in things like -march is very unusual; I would be much more in favour of keeping things lowercase

@cmuellner
Copy link
Collaborator

The architecture review committee has sent out the following text about how profiles support in toolchains should look like:

In response to some recent discussion in the Apps and Tools HC about how profiles should be represented in GCC/LLVM, the ARC provides this answer: compilers should use a single parameter for an ISA string. An ISA string begins with either a base ISA name (e.g. rv64i) or a profile name (e.g. rva23u64) and is optionally followed by additional extensions (e.g. rv64imac_zicond or rva23u64_zfh_zicond). If the ISA string begins with a profile name, it is equivalent to replacing the profile name with its mandatory base ISA and its mandatory extensions; any optional extensions in a profile must be explicitly named if their inclusion is desired. ISAs are sets, and concatenating strings takes the union, so redundancy is legal (e.g. rva23u64, rva23u64_zicsr, and rva23u64_zicsr_zicsr are all valid and equivalent).

https://lists.riscv.org/g/tech-unprivileged/message/611

@wangpc-pp
Copy link

Draft LLVM implementation: llvm/llvm-project#76357.

wangpc-pp added a commit to wangpc-pp/llvm-project that referenced this pull request Dec 28, 2023
This PR implements the draft
riscv-non-isa/riscv-toolchain-conventions#36.

Currently, we replace specified profile in `-march` with standard
arch string.

We may need to pass it to backend so that we can emit an ELF attr
proposed by
riscv-non-isa/riscv-elf-psabi-doc#409.
@wangpc-pp
Copy link

Reverse ping. Is there any progress?

@cmuellner
Copy link
Collaborator

The GCC implementation is tracked here: riscv-admin/dev-partners#16.

There was a request to wait on the GCC patch regarding the adoption of profiles in toolchain components: https://gcc.gnu.org/pipermail/gcc-patches/2023-December/641025.html.

So, at this point, we have clear guidelines from RVI regarding the adoption. We have this PR, and we have patches for GCC and LLVM. This can all move forward if upstream maintainers are fine with it.

Given the relatively low impact on toolchains, I'm fine with waiting until the GCC 15 branch opens up.
LLVM might move on earlier.

wangpc-pp added a commit to wangpc-pp/llvm-project that referenced this pull request Feb 20, 2024
This PR implements the draft
riscv-non-isa/riscv-toolchain-conventions#36.

Currently, we replace specified profile in `-march` with standard
arch string.
@pz9115
Copy link
Contributor Author

pz9115 commented Jan 7, 2025

The text in this PR currently differs from the ARC decision mentioned in #36 (comment) and the implementation in LLVM in llvm/llvm-project#76357 in two significant ways:

  • Profile names are specified in lowercase, not uppercase
  • Additional extensions are specified with _ as the separator, not +

I worry that this inconsistency might cause compatibility issues.

Sync the format with LLVM implement, using lowercase and _ in Profiles format.


Profiles format has the following BNF form `"-march="<profile-name>"_"[option-ext]*`.

`profile-name ::= "RV"<profile-family-name><profile-ratified-year><privilege-mode><ISA-XLEN>`
Copy link

@wangpc-pp wangpc-pp Jan 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The naming convention of profiles may not be like this any more if I read what the sig-profiles (https://lists.riscv.org/g/sig-profiles/message/83) is doing rightly. The proposed profile naming is here (I don't know if every one can read it): https://docs.google.com/document/d/19xXIMnk1MNRZIp9fnW0yzBvnRnqko0LJT0XUjUvDVZ4/
So, I think, here we can just say that profile-name will be a valid list of released profiles. As for the format, we should refer to the document of profiles.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok,it sounds great, will update it in new version.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then we don't need these eBNFs?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.

@pz9115 pz9115 requested review from wangpc-pp and kito-cheng January 7, 2025 12:37
`option-ext ::= 'a legal RISC-V extension name'`

As the spec defines, to use the profiles it should follow profile naming convention
(See [3.4 form spec doc](https://github.com/riscv/riscv-profiles)), the toolchain
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

", the toolchain will check" should be the start of a new sentence.


`option-ext ::= 'a legal RISC-V extension name'`

As the spec defines, to use the profiles it should follow profile naming convention
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sentence is kind of awkward.

@@ -216,6 +216,43 @@ As of November 2021 the additional tail-call entry points are only
implemented in compiler-rt, and calls will only be generated by LLVM
when the option `-mllvm -save-restore-tailcall` is specified.

== Profile-based format

Profiles name will be a valid list of released profiles, it should be recognized and used
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Profiles name" -> "Profile names" if we are talking about a list of names of multiple profiles.


`profile-family-name ::= "i" | "m" | "a"`

`profile-ratified-year-version ::= "20" | "22" | "23A" | "23B"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aren't the profiles named rva23 and rvb23. There is no A or B after 23.


`profile-name ::= "RV"<profile-family-name><profile-ratified-year><privilege-mode><ISA-XLEN>`

`profile-family-name ::= "i" | "m" | "a"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing "b"


To distinguish between ordinary extension input and input with profiles,
profiles are assumed to be entered *at the beginning of the -march option*, and
then input other extensions. Profiles should input in the `-march` option.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Profiles should input in the -march option." seems redundant with the previous sentece.


`-march=rvi20u64_zbkb_zkne -mabi=lp64` equals `-march=rv64i_zbkb_zkne -mabi=lp64`

`-march=rva22u32` equals `-march=rv64gcb_zic64b_zicbom_zicbop_zicboz_ziccamoa_ziccif_zicclsm_ziccrse_zicntr_zihpm_za64rs_zfhmin_zkt`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no rva22u32 profile. I think this should be rva22u64?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your comments, fixed in new commit.

@pz9115 pz9115 requested a review from topperc January 8, 2025 01:56
@pz9115 pz9115 requested a review from pthariensflame January 13, 2025 08:23
Copy link
Collaborator

@kito-cheng kito-cheng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with one minor comment

@pz9115 pz9115 requested a review from kito-cheng January 27, 2025 04:14
in the `-march=` option. The benefit of using the `-march` option is easy for toolchain
parsing the profiles string and expanding it into normal extensions combinations.

Profiles format has the following BNF form `"-march="<profile-name>"_"[option-ext]*`.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The BNF should be "-march="<profile-name>["_"option-ext]*? The underline is optional when there is no optional extra extension.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, thanks for the mention, update with new commit.

@pz9115 pz9115 requested a review from wangpc-pp February 5, 2025 03:51
Copy link

@wangpc-pp wangpc-pp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks!

@pz9115
Copy link
Contributor Author

pz9115 commented May 7, 2025

Ping..

@kito-cheng
Copy link
Collaborator

Could you rebase and squash all commit into one?

Copy link
Collaborator

@kito-cheng kito-cheng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Fix typo and adjust examples.

Signed-off-by: Jiawei <[email protected]>
@pz9115 pz9115 requested a review from topperc May 9, 2025 13:19
@cmuellner
Copy link
Collaborator

Profiles support landed in GCC: https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=43b450e3f72a53c744e77f55393962f1d349373a

Thanks @pz9115!

@cmuellner
Copy link
Collaborator

@pz9115, the CI complains about a trailing whitespace.

@kito-cheng and others, given the long history of the profile support discussion, I think we should just land this PR as is.
I can still see that there is room for some tweaks regarding the wording, but I don't think this needs to block this PR. Cleanups can be applied later on. Objections?

@kito-cheng
Copy link
Collaborator

@cmuellner no objection on moving forward this first, we can tweak this later.

@cmuellner cmuellner merged commit 040c928 into riscv-non-isa:main May 12, 2025
1 of 2 checks passed
@cmuellner cmuellner mentioned this pull request Jun 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.