This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Add MC layer support for Zicfiss.
AbandonedPublic

Authored by fakepaper56 on Jun 13 2023, 2:38 AM.

Details

Summary

The patch adds the instructions in Zicfiss extension. Zicfisslp extension is
to support shadow stack for control flow integrity.

Diff Detail

Event Timeline

fakepaper56 created this revision.Jun 13 2023, 2:38 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 13 2023, 2:38 AM
fakepaper56 requested review of this revision.Jun 13 2023, 2:38 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptJun 13 2023, 2:38 AM
fakepaper56 added a comment.EditedJun 13 2023, 2:40 AM

The patch might be too early to be posted. The idea is to make people easier to develop shadow-stack/landing-pads, although it will land for long time.

Update instruction information and mark ssp as reserved register.

Make the patch only focus on Zicfiss.

fakepaper56 retitled this revision from [RISCV] Add MC layer support for Zicfisslp. to [RISCV] Add MC layer support for Zicfiss..Jul 21 2023, 12:46 AM
fakepaper56 edited the summary of this revision. (Show Details)
craig.topper added inline comments.
clang/test/Preprocessor/riscv-target-features.c
73

This needs to be renamed to remove lp

721

This needs to be renamed to remove lp

llvm/lib/Target/RISCV/RISCVFeatures.td
84

Zicfiss

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

This needs to be rebased, the files here were moved into groups.

llvm/lib/Target/RISCV/RISCVInstrInfoZicfiss.td
2

Filename doesn't match

36

Can we use RVInstI by adding let imm12 = 0b100000011100 to the body?

67

Can this use RVInstI with lets for imm12, rs1, and rd?

76

Can this use RVInstR?

88

Can this use RVInstR?

99

RVInstR

This comment was removed by fakepaper56.
fakepaper56 marked 5 inline comments as done.
This comment was removed by fakepaper56.
fakepaper56 marked an inline comment as done.Jul 25 2023, 10:33 PM

Address Craig's comment.

fakepaper56 marked 3 inline comments as done.Jul 26 2023, 12:13 AM

Please update llvm/docs/RISCVUsage.rst

craig.topper added inline comments.Aug 1 2023, 6:03 PM
llvm/lib/Target/RISCV/RISCVInstrInfo.td
233

Is this used?

llvm/lib/Target/RISCV/RISCVInstrInfoZicfiss.td
36

Why are there ins and outs here that aren't encoded?

57

Need to be able to parse with ra instead of x1 and t0 instead of x5.

I think you might need a new Operand type so the parse can parse it as a register.

craig.topper added inline comments.Aug 1 2023, 10:53 PM
llvm/lib/Target/RISCV/RISCVInstrInfo.td
1977

Put this with the other RISCVInstrInfoZi* files under "Integer"

llvm/lib/Target/RISCV/RISCVInstrInfoZicfiss.td
93

Can we merge the X1 and X5 instructions? Looks like the register is encoded?

Jim added inline comments.Aug 1 2023, 11:25 PM
llvm/lib/Target/RISCV/RISCVInstrInfoZicfiss.td
34

Two let lines can be merged?

59

Add a blank line before this line.

fakepaper56 added inline comments.Aug 6 2023, 11:04 PM
llvm/lib/Target/RISCV/RISCVInstrInfoZicfiss.td
57

Need to be able to parse with ra instead of x1 and t0 instead of x5.

Actually, we can parse ssload ra in llvm/test/MC/RISCV/zicfiss-valid.s, but the code indeed can not print ssload ra. I have tried to define ssload and sspopchk separately, but it caused decode conflict.

Bump to 0.2 and address part of comments.

fakepaper56 marked 3 inline comments as done.Aug 7 2023, 7:09 PM

Make asmprinter capable to print alias register name for ssload/sspopchk/c.sspush/c.sspopchk.

fakepaper56 marked an inline comment as done.
fakepaper56 added inline comments.
llvm/lib/Target/RISCV/RISCVInstrInfoZicfiss.td
57

The problem is fixed in latest update.

Please update docs/RISCVUsage.rst

Update docs/RISCVUsage.rst.

This comment was removed by fakepaper56.

Update docs/RISCVUsage.rst to move zicfiss to experimental extension.

craig.topper added inline comments.Aug 15 2023, 4:49 PM
llvm/lib/Target/RISCV/RISCVInstrInfoZicfiss.td
89

Is it compatible with Zca?

craig.topper added inline comments.Aug 15 2023, 4:51 PM
llvm/lib/Target/RISCV/RISCVInstrInfoZicfiss.td
33

Can you call this rs1val instead of rs1 since $rs1 is part of the ins.

fakepaper56 added inline comments.Aug 15 2023, 6:17 PM
llvm/lib/Target/RISCV/RISCVInstrInfoZicfiss.td
89

The spec does not mention it is incompatible with Zca. I think I need to enable c.push/c.popchk for Zca.

Address comments.

fakepaper56 marked an inline comment as done.Aug 15 2023, 7:24 PM
craig.topper added inline comments.Aug 16 2023, 4:46 PM
llvm/lib/Target/RISCV/RISCVInstrInfoZicfiss.td
38

Do we need the rs1 variable or can we use rs1val here? We usually have the rs1 field because the encoder maps ins/outs operand names to the field name. In this case we have an explicit immediate passed as rs1val. Is the encoding value coming from the operand or from the immediate? I can't tell with the name conflict.

Address comment.

fakepaper56 marked an inline comment as done.Aug 16 2023, 9:13 PM
This revision is now accepted and ready to land.Aug 16 2023, 9:20 PM
jrtc27 requested changes to this revision.Aug 16 2023, 10:09 PM
jrtc27 added inline comments.
llvm/lib/Target/RISCV/RISCVInstrInfoZicfiss.td
2

CFG?

49–50

This is some strange wrapping; normally we'd put RVInstI on the same line and wrap some of the arguments, but if you really want to wrap then indent by 4 spaces and put the colon on the lower line, that's what the predominant style is

63

This is how I'd expect the earlier instructions to be formatted, FWIW... please be consistent

95

Missing space

This revision now requires changes to proceed.Aug 16 2023, 10:09 PM

Address jrtc27's comment.

fakepaper56 marked 3 inline comments as done.Aug 16 2023, 10:34 PM
fakepaper56 planned changes to this revision.Aug 19 2023, 9:18 PM
This comment was removed by fakepaper56.
SuH added a subscriber: SuH.Sep 6 2023, 1:44 AM
SuH added inline comments.
llvm/lib/Target/RISCV/RISCVInstrInfoZicfiss.td
76

After v0.2 SSPUSH encoding already changed from 0b1000101 to 0b1000001

fakepaper56 abandoned this revision.Sep 12 2023, 5:53 AM

Closed it and create a PR https://github.com/llvm/llvm-project/pull/66043 for version 0.3.1.