-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[RISCV] Add MC layer support for Zicfiss. #66043
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
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
//===------ RISCVInstrInfoZicfiss.td - RISC-V Zicfiss -*- tablegen -*------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
//===----------------------------------------------------------------------===// | ||
// Instruction class templates | ||
//===----------------------------------------------------------------------===// | ||
|
||
class RVC_SSInst<bits<5> rs1val, RegisterClass reg_class, string opcodestr> : | ||
RVInst16<(outs), (ins reg_class:$rs1), opcodestr, "$rs1", [], InstFormatOther> { | ||
let Inst{15-13} = 0b011; | ||
let Inst{12} = 0; | ||
let Inst{11-7} = rs1val; | ||
let Inst{6-2} = 0b00000; | ||
let Inst{1-0} = 0b01; | ||
let DecoderMethod = "decodeCSSPushPopchk"; | ||
} | ||
|
||
//===----------------------------------------------------------------------===// | ||
// Instructions | ||
//===----------------------------------------------------------------------===// | ||
|
||
let Predicates = [HasStdExtZicfiss] in { | ||
let Uses = [SSP], Defs = [SSP], hasSideEffects = 0, mayLoad = 1, mayStore = 0 in | ||
def SSPOPCHK : RVInstI<0b100, OPC_SYSTEM, (outs), (ins GPRX1X5:$rs1), "sspopchk", | ||
"$rs1"> { | ||
let rd = 0; | ||
let imm12 = 0b110011011100; | ||
} // Uses = [SSP], Defs = [SSP], hasSideEffects = 0, mayLoad = 1, mayStore = 0 | ||
|
||
let Uses = [SSP], hasSideEffects = 0, mayLoad = 0, mayStore = 0 in { | ||
def SSRDP : RVInstI<0b100, OPC_SYSTEM, (outs GPRNoX0:$rd), (ins), "ssrdp", "$rd"> { | ||
let imm12 = 0b110011011100; | ||
let rs1 = 0b00000; | ||
} | ||
} // Uses = [SSP], hasSideEffects = 0, mayLoad = 0, mayStore = 0 | ||
|
||
let Uses = [SSP], Defs = [SSP], hasSideEffects = 0, mayLoad = 0, mayStore = 1 in | ||
def SSPUSH : RVInstR<0b1100111, 0b100, OPC_SYSTEM, (outs), (ins GPRX1X5:$rs2), | ||
"sspush", "$rs2"> { | ||
let rd = 0b00000; | ||
let rs1 = 0b00000; | ||
} | ||
} // Predicates = [HasStdExtZicfiss] | ||
|
||
let Predicates = [HasStdExtZicfiss, HasStdExtZcmop], | ||
DecoderNamespace = "Zicfiss" in { | ||
let Uses = [SSP], Defs = [SSP], hasSideEffects = 0, mayLoad = 0, mayStore = 1 in | ||
def C_SSPUSH : RVC_SSInst<0b00001, GPRX1, "c.sspush">; | ||
|
||
let Uses = [SSP], Defs = [SSP], hasSideEffects = 0, mayLoad = 1, mayStore = 0 in | ||
def C_SSPOPCHK : RVC_SSInst<0b00101, GPRX5, "c.sspopchk">; | ||
} // Predicates = [HasStdExtZicfiss, HasStdExtZcmop] | ||
|
||
let Predicates = [HasStdExtZicfiss] in | ||
defm SSAMOSWAP_W : AMO_rr_aq_rl<0b01001, 0b010, "ssamoswap.w">; | ||
|
||
let Predicates = [HasStdExtZicfiss, IsRV64] in | ||
defm SSAMOSWAP_D : AMO_rr_aq_rl<0b01001, 0b011, "ssamoswap.d">; | ||
|
||
//===----------------------------------------------------------------------===/ | ||
// Compress Instruction tablegen backend. | ||
//===----------------------------------------------------------------------===// | ||
|
||
let Predicates = [HasStdExtZicfiss, HasStdExtZcmop] in { | ||
def : CompressPat<(SSPUSH X1), (C_SSPUSH X1)>; | ||
def : CompressPat<(SSPOPCHK X5), (C_SSPOPCHK X5)>; | ||
} // Predicates = [HasStdExtZicfiss, HasStdExtZcmop] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# RUN: llvm-mc %s -triple=riscv32 -mattr=+experimental-zicfiss,+experimental-zcmop -riscv-no-aliases -show-encoding \ | ||
# RUN: | FileCheck -check-prefixes=CHECK-ASM,CHECK-ASM-AND-OBJ %s | ||
# RUN: llvm-mc -filetype=obj -triple=riscv32 -mattr=+experimental-zicfiss,+experimental-zcmop < %s \ | ||
# RUN: | llvm-objdump --mattr=+experimental-zicfiss,+experimental-zcmop -M no-aliases -d -r - \ | ||
# RUN: | FileCheck --check-prefix=CHECK-ASM-AND-OBJ %s | ||
# RUN: llvm-mc %s -triple=riscv64 -mattr=+experimental-zicfiss,+experimental-zcmop -riscv-no-aliases -show-encoding \ | ||
# RUN: | FileCheck -check-prefixes=CHECK-ASM,CHECK-ASM-AND-OBJ %s | ||
# RUN: llvm-mc -filetype=obj -triple=riscv64 -mattr=+experimental-zicfiss,+experimental-zcmop < %s \ | ||
# RUN: | llvm-objdump --mattr=+experimental-zicfiss,+experimental-zcmop -M no-aliases -d -r - \ | ||
# RUN: | FileCheck --check-prefix=CHECK-ASM-AND-OBJ %s | ||
# | ||
# RUN: not llvm-mc -triple riscv32 -riscv-no-aliases -show-encoding < %s 2>&1 \ | ||
# RUN: | FileCheck -check-prefixes=CHECK-NO-EXT %s | ||
|
||
# CHECK-ASM-AND-OBJ: c.sspopchk t0 | ||
# CHECK-ASM: encoding: [0x81,0x62] | ||
# CHECK-NO-EXT: error: instruction requires the following: 'Zicfiss' (Shadow stack) | ||
sspopchk x5 | ||
|
||
# CHECK-ASM-AND-OBJ: c.sspopchk t0 | ||
# CHECK-ASM: encoding: [0x81,0x62] | ||
# CHECK-NO-EXT: error: instruction requires the following: 'Zicfiss' (Shadow stack) | ||
sspopchk t0 | ||
|
||
# CHECK-ASM-AND-OBJ: c.sspush ra | ||
# CHECK-ASM: encoding: [0x81,0x60] | ||
# CHECK-NO-EXT: error: instruction requires the following: 'Zicfiss' (Shadow stack) | ||
sspush x1 | ||
|
||
# CHECK-ASM-AND-OBJ: c.sspush ra | ||
# CHECK-ASM: encoding: [0x81,0x60] | ||
# CHECK-NO-EXT: error: instruction requires the following: 'Zicfiss' (Shadow stack) | ||
sspush ra | ||
|
||
# CHECK-ASM-AND-OBJ: c.sspush ra | ||
# CHECK-ASM: encoding: [0x81,0x60] | ||
# CHECK-NO-EXT: error: instruction requires the following: 'Zcmop' (Compressed May-Be-Operations), 'Zicfiss' (Shadow stack) | ||
c.sspush x1 | ||
|
||
# CHECK-ASM-AND-OBJ: c.sspush ra | ||
# CHECK-ASM: encoding: [0x81,0x60] | ||
# CHECK-NO-EXT: error: instruction requires the following: 'Zcmop' (Compressed May-Be-Operations), 'Zicfiss' (Shadow stack) | ||
c.sspush ra | ||
|
||
# CHECK-ASM-AND-OBJ: c.sspopchk t0 | ||
# CHECK-ASM: encoding: [0x81,0x62] | ||
# CHECK-NO-EXT: error: instruction requires the following: 'Zcmop' (Compressed May-Be-Operations), 'Zicfiss' (Shadow stack) | ||
c.sspopchk x5 | ||
|
||
# CHECK-ASM-AND-OBJ: c.sspopchk t0 | ||
# CHECK-ASM: encoding: [0x81,0x62] | ||
# CHECK-NO-EXT: error: instruction requires the following: 'Zcmop' (Compressed May-Be-Operations), 'Zicfiss' (Shadow stack) | ||
c.sspopchk t0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# RUN: not llvm-mc %s -triple=riscv32 -mattr=+experimental-zicfiss,+c -riscv-no-aliases -show-encoding \ | ||
# RUN: 2>&1 | FileCheck -check-prefixes=CHECK-ERR %s | ||
|
||
# CHECK-ERR: error: invalid operand for instruction | ||
sspopchk a1 | ||
|
||
# CHECK-ERR: error: invalid operand for instruction | ||
c.sspush t0 | ||
|
||
# CHECK-ERR: error: invalid operand for instruction | ||
c.sspopchk ra | ||
|
||
# CHECK-ERR: error: invalid operand for instruction | ||
sspush a0 | ||
|
||
# CHECK-ERR: error: invalid operand for instruction | ||
ssrdp zero |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# RUN: not llvm-mc %s -triple=riscv64 -mattr=+experimental-zicfiss,+c -riscv-no-aliases -show-encoding \ | ||
# RUN: 2>&1 | FileCheck -check-prefixes=CHECK-ERR %s | ||
|
||
# CHECK-ERR: error: invalid operand for instruction | ||
sspopchk a1 | ||
|
||
# CHECK-ERR: error: invalid operand for instruction | ||
c.sspush t0 | ||
|
||
# CHECK-ERR: error: invalid operand for instruction | ||
c.sspopchk ra | ||
|
||
# CHECK-ERR: error: invalid operand for instruction | ||
sspush a0 | ||
|
||
# CHECK-ERR: error: invalid operand for instruction | ||
ssrdp zero |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should these instructions be aliases of MOPs now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They should use same encoding as some instructions of Zimop, but currently, there is no
mop.r
could be fitted tosspush
andsspopchk
. The 24th bit ofsspush
is 0 but the 24th bit of allmop.r
is 1. The 25th bit ofsspopchk
is 0 but but the 25th bit of allmop.r
is 1.ref:
https://github.com/riscv/riscv-isa-manual/blob/main/src/images/wavedrom/mop-r.adoc
https://github.com/riscv/riscv-cfi/blob/main/cfi_backward.adoc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm, I haven't looked at it in details, is this a document mistake? They should have the same encoding.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I don't find any mistake,
sspush
usesmop.rr
andsspopchk
usesmop.r
.This is wrong as it's
{ bits: 4, name: 0x7 }
, so its value is0b0111
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I will give a fix for this.