This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Implement assembler support for XVentanaCondOps
ClosedPublic

Authored by reames on Nov 3 2022, 12:00 PM.

Details

Summary

This change provides an implementation of the XVentanaCondOps vendor extension. This extension is defined in version 1.0.0 of the VTx-family custom instructions specification (https://github.com/ventanamicro/ventana-custom-extensions/releases/download/v1.0.0/ventana-custom-extensions-v1.0.0.pdf) by Ventana Micro Systems.

This change is intended to be a test case for our vendor extension policy. I believe this to be a case we clearly should accept, but it gives us an opportunity to discuss and set precedent on various policy and naming questions. (I will comment on the review to highlight questions I think are worth discussion.)

I intent to bring this up at the next RISCV sync call, and ensure we have consensus. Once this lands, I plan to use this extension to prototype selection lowering to conditional moves. There's an RVI proposal in flight, and the expectation is that lowering to these and the new RVI instructions is likely to be substantially similar.

Diff Detail

Event Timeline

reames created this revision.Nov 3 2022, 12:00 PM
reames requested review of this revision.Nov 3 2022, 12:00 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptNov 3 2022, 12:00 PM
reames added inline comments.Nov 3 2022, 12:10 PM
clang/test/Preprocessor/riscv-target-features.c
437

Naming wise, is xventanacondops what we want this called? The toolchain docs linked are a bit ambiguous on this point. They seem to be saying that the extension should maybe be xvtcondops. But that's not what the spec uses, not what we tend to use in discussion, and not what is being discussed for binutils.

439

This patch only includes positive tests for riscv64. Per the current specification, no rv32 chips have shipped with this feature. I chose not to actually reject the flags or elf settings for riscv32, but to not enable the assembler either.

What do we think is the right answer here? Should we accept the riscv32 forms? This would essentially be an LLVM extension. Should we explicitly error on the riscv32 form? Something else?

llvm/docs/RISCVUsage.rst
161

Anything else we want in the documentation? Remember, we're setting precedent here.

llvm/lib/Target/RISCV/RISCVInstrInfo.td
1785

How do we want to manage td files for vendor extensions?

I put them inline - which is probably not the right answer. I'm leaning towards a vendor specific td file with extensions split out if complexity justifies it. So, this patch would add a RISCVInstInfoXVentana.td.

Is that the precedent we want here?

reames updated this revision to Diff 473001.Nov 3 2022, 12:12 PM

Fix silly typo

craig.topper added inline comments.Nov 3 2022, 12:34 PM
clang/test/Preprocessor/riscv-target-features.c
437

qemu seems to have also used xventanacondops.

llvm/lib/Target/RISCV/RISCV.td
422

It's not quite conditional move. It's conditional move or zero right? Might be better just says "Ops" or "Operations" instead of "Move".

426

Blank line above this.

llvm/lib/Target/RISCV/RISCVInstrFormats.td
148

Since the string here is used for .insn parsing, I think it should be CUSTOM_3. I'm not sure why we don't already have all 4 added.

Do these need their own DecoderNameSpace?

reames added a comment.Nov 3 2022, 1:39 PM

Do these need their own DecoderNameSpace?

What is a decoder namespace? Some quick grepping and googling isn't very informative.

llvm/lib/Target/RISCV/RISCVInstrFormats.td
148
reames updated this revision to Diff 473022.Nov 3 2022, 1:43 PM

Address review comments from @craig.topper

reames marked 4 inline comments as done and 3 inline comments as done.Nov 3 2022, 1:44 PM

Do these need their own DecoderNameSpace?

What is a decoder namespace? Some quick grepping and googling isn't very informative.

If another vendor also uses these opcodes for something else, I think we would need to partition the disassembler tables.

Some existing examples

RISCVInstrInfoC.td
330:let DecoderNamespace = "RISCV32Only_",
364:let DecoderNamespace = "RISCV32Only_",
409:    DecoderNamespace = "RISCV32Only_", Defs = [X1],
517:let DecoderNamespace = "RISCV32Only_",
577:let DecoderNamespace = "RISCV32Only_",

RISCVDisassembler::getInstruction checks some subtarget bits to select different tables where there are conflicts.

jrtc27 added a comment.Nov 4 2022, 8:35 AM

Do these need their own DecoderNameSpace?

I was going to come here to request that

reames updated this revision to Diff 473272.Nov 4 2022, 9:55 AM

Add a decoder namespace.

I did one per vendor - i.e. used a Ventana table rather than a VentanaCondOps one. In theory, we could have a vendor who ships incompatible extensions (in two different pieces of hardware), but if we hit that case, we can adjust later. Or at least, I think we can? This is new to me.

kito-cheng added inline comments.Nov 10 2022, 10:53 AM
llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
469 ↗(On Diff #473285)

Typo, should be "Trying Ventana..."

llvm/lib/Target/RISCV/RISCVInstrInfo.td
1785

I would suggest put into RISCVInstInfoXVentana.td instead of inline here, I could imagine once this get merged, T-head extensions might try to upstream too, so put into separated now could prevent they reference this commit and try to inline their extensions IMO :)

reames updated this revision to Diff 474620.Nov 10 2022, 3:25 PM

Address Kito's review comments

craig.topper added inline comments.Nov 10 2022, 10:27 PM
llvm/lib/Target/RISCV/RISCVInstrInfoXVentana.td
14 ↗(On Diff #474620)

Does the - here mean something?

19 ↗(On Diff #474620)

I don't think we need to this applied to the class and the instantatiations of the class. I think you can drop the curly braces and only apply it to the class.

24 ↗(On Diff #474620)

space between > and {

reames updated this revision to Diff 474782.Nov 11 2022, 8:51 AM

Address comments from @craig.topper

This revision is now accepted and ready to land.Nov 13 2022, 11:42 AM
This revision was landed with ongoing or failed builds.Nov 14 2022, 9:03 AM
This revision was automatically updated to reflect the committed changes.