Skip to content

Commit 8bba6bf

Browse files
committedDec 12, 2017
[RISCV] MC layer support for the instructions added in the privileged spec
Adds support for the instructions added in the RISC-V privileged ISA (https://content.riscv.org/wp-content/uploads/2017/05/riscv-privileged-v1.10.pdf): uret, sret, mret, wfi, and sfence.vma. Note from the committer: I made very minor formatting changes prior to commit, which didn't seem worth creating another review round-trip for. Differential Revision: https://reviews.llvm.org/D40383 Patch by David Craven. llvm-svn: 320484
1 parent 1daef8a commit 8bba6bf

File tree

3 files changed

+81
-0
lines changed

3 files changed

+81
-0
lines changed
 

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

+42
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,11 @@ class ALUW_rr<bits<7> funct7, bits<3> funct3, string opcodestr>
211211
: RVInstR<funct7, funct3, OPC_OP_32, (outs GPR:$rd),
212212
(ins GPR:$rs1, GPR:$rs2), opcodestr, "$rd, $rs1, $rs2">;
213213

214+
let hasSideEffects = 1, mayLoad = 0, mayStore = 0 in
215+
class Priv<string opcodestr, bits<7> funct7>
216+
: RVInstR<funct7, 0b000, OPC_SYSTEM, (outs), (ins GPR:$rs1, GPR:$rs2),
217+
opcodestr, "">;
218+
214219
//===----------------------------------------------------------------------===//
215220
// Instructions
216221
//===----------------------------------------------------------------------===//
@@ -333,6 +338,43 @@ def SRLW : ALUW_rr<0b0000000, 0b101, "srlw">;
333338
def SRAW : ALUW_rr<0b0100000, 0b101, "sraw">;
334339
} // Predicates = [IsRV64]
335340

341+
//===----------------------------------------------------------------------===//
342+
// Privileged instructions
343+
//===----------------------------------------------------------------------===//
344+
345+
let isBarrier = 1, isReturn = 1, isTerminator = 1 in {
346+
def URET : Priv<"uret", 0b0000000> {
347+
let rd = 0;
348+
let rs1 = 0;
349+
let rs2 = 0b00010;
350+
}
351+
352+
def SRET : Priv<"sret", 0b0001000> {
353+
let rd = 0;
354+
let rs1 = 0;
355+
let rs2 = 0b00010;
356+
}
357+
358+
def MRET : Priv<"mret", 0b0011000> {
359+
let rd = 0;
360+
let rs1 = 0;
361+
let rs2 = 0b00010;
362+
}
363+
} // isBarrier = 1, isReturn = 1, isTerminator = 1
364+
365+
def WFI : Priv<"wfi", 0b0001000> {
366+
let rd = 0;
367+
let rs1 = 0;
368+
let rs2 = 0b00101;
369+
}
370+
371+
let hasSideEffects = 1, mayLoad = 0, mayStore = 0 in
372+
def SFENCE_VMA : RVInstR<0b0001001, 0b000, OPC_SYSTEM, (outs),
373+
(ins GPR:$rs1, GPR:$rs2),
374+
"sfence.vma", "$rs1, $rs2"> {
375+
let rd = 0;
376+
}
377+
336378
//===----------------------------------------------------------------------===//
337379
// Pseudo-instructions and codegen patterns
338380
//

‎llvm/test/MC/RISCV/priv-invalid.s

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# RUN: not llvm-mc -triple riscv32 < %s 2>&1 | FileCheck %s
2+
3+
mret 0x10 # CHECK: :[[@LINE]]:6: error: invalid operand for instruction
4+
5+
sfence.vma zero # CHECK: :[[@LINE]]:1: error: too few operands for instruction
6+
7+
sfence.vma a0, 0x10 # CHECK: :[[@LINE]]:16: error: invalid operand for instruction

‎llvm/test/MC/RISCV/priv-valid.s

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# RUN: llvm-mc %s -triple=riscv32 -show-encoding \
2+
# RUN: | FileCheck -check-prefixes=CHECK,CHECK-INST %s
3+
# RUN: llvm-mc %s -triple=riscv64 -show-encoding \
4+
# RUN: | FileCheck -check-prefixes=CHECK,CHECK-INST %s
5+
# RUN: llvm-mc -filetype=obj -triple riscv32 < %s \
6+
# RUN: | llvm-objdump -d - | FileCheck -check-prefix=CHECK-INST %s
7+
# RUN: llvm-mc -filetype=obj -triple riscv64 < %s \
8+
# RUN: | llvm-objdump -d - | FileCheck -check-prefix=CHECK-INST %s
9+
10+
# CHECK-INST: uret
11+
# CHECK: encoding: [0x73,0x00,0x20,0x00]
12+
uret
13+
14+
# CHECK-INST: sret
15+
# CHECK: encoding: [0x73,0x00,0x20,0x10]
16+
sret
17+
18+
# CHECK-INST: mret
19+
# CHECK: encoding: [0x73,0x00,0x20,0x30]
20+
mret
21+
22+
# CHECK-INST: wfi
23+
# CHECK: encoding: [0x73,0x00,0x50,0x10]
24+
wfi
25+
26+
# CHECK-INST: sfence.vma zero, zero
27+
# CHECK: encoding: [0x73,0x00,0x00,0x12]
28+
sfence.vma zero, zero
29+
30+
# CHECK-INST: sfence.vma a0, a1
31+
# CHECK: encoding: [0x73,0x00,0xb5,0x12]
32+
sfence.vma a0, a1

0 commit comments

Comments
 (0)
Please sign in to comment.