This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Relax rules for ordering s/z/x prefixed extensions in ISA naming strings
ClosedPublic

Authored by asb on Apr 26 2023, 2:29 AM.

Details

Summary

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 actually removes all ordering restrictions so you can freely mix x/s/z extensions. Arguably this is more freedom than we want to allow, on the other hand it might be less hassle for build systems assembling their arch strings.

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.

Diff Detail

Event Timeline

asb created this revision.Apr 26 2023, 2:29 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 26 2023, 2:29 AM
asb requested review of this revision.Apr 26 2023, 2:29 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptApr 26 2023, 2:29 AM
asb updated this revision to Diff 517105.Apr 26 2023, 2:29 AM
asb updated this revision to Diff 517106.

Add missing doc comment update.

reames accepted this revision.Apr 26 2023, 7:28 AM

I generally think this is a good idea. I'd ask you add this to RISCVUsage under "The current known variances from the specification are", and mention it at the next sync up call, but otherwise, I think we should proceed with this.

LGTM once the above are done.

This revision is now accepted and ready to land.Apr 26 2023, 7:28 AM

IDK about the specifics here, but I think in general being more permissive on ISA string parsing is the way to go. The rules have changed so many times it's not really viable to follow them, so we're sort of just stuck with a bunch of historally-driven implementation-specific behavior.

I've got a TODO floating around somewhere to document what GCC accepts, but it's super clunky and I get tired every time I try and look...

Perhaps redundant now that Palmer has commented, an opinion was solicited from me so here I am, pretty much copy-pasting from elsewhere:

IMO, alignment with gcc is helpful, permissiveness is better.
Given "canonical order" can, and has, change(d) in the past I think it's good to insulate against it happening again.
Conjuring up march is bad enough as things stand w/ availability with given toolchain versions, especially in situations where different toolchain components are mixed between various versions llvm and gnu stuff.
Having to do special handing of different versions of gcc/clang whenever we do actually need to add Sfoo or Xfoo sounds like another layer of misery I would love to avoid.
Although it looks like we'll probably have to do some Makefile dance around older gcc/clang versions but at least going forward it'd be the same.

kito-cheng accepted this revision.Apr 27 2023, 2:33 AM

I am really happy to see this happen, binutils has relaxed for a while in more relaxed way[1] - only require must start with rv[32|64][e|i|g], personally I would like to relax the order at all like binutils did for GCC, but I don't want to disturb that before making sure clang will going same way - otherwise just making more incomparable.

The order is kind of not friendly for user, I don't believe how many people remember the right order between z* extension in short time - even after read the RISC-V ISA spec.

[1] https://sourceware.org/pipermail/binutils/2022-December/125267.html

asb added a comment.Jun 23 2023, 6:28 AM

All feedback so far has been positive and this has two LGTMs, but I also recognise this patch has been left for a while. Heads up that I intend to commit this towards the end of the working day Monday UK time unless anyone has any objections / concerns.

evandro removed a subscriber: evandro.Jun 23 2023, 5:44 PM
This revision was landed with ongoing or failed builds.Jun 27 2023, 5:32 AM
This revision was automatically updated to reflect the committed changes.