[llvm] r320484 - [RISCV] MC layer support for the instructions added in the privileged spec
Alex Bradbury via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 12 07:17:45 PST 2017
Author: asb
Date: Tue Dec 12 07:17:45 2017
New Revision: 320484
URL: http://llvm.org/viewvc/llvm-project?rev=320484&view=rev
Log:
[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.
Added:
llvm/trunk/test/MC/RISCV/priv-invalid.s
llvm/trunk/test/MC/RISCV/priv-valid.s
Modified:
llvm/trunk/lib/Target/RISCV/RISCVInstrInfo.td
Modified: llvm/trunk/lib/Target/RISCV/RISCVInstrInfo.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/RISCV/RISCVInstrInfo.td?rev=320484&r1=320483&r2=320484&view=diff
==============================================================================
--- llvm/trunk/lib/Target/RISCV/RISCVInstrInfo.td (original)
+++ llvm/trunk/lib/Target/RISCV/RISCVInstrInfo.td Tue Dec 12 07:17:45 2017
@@ -211,6 +211,11 @@ class ALUW_rr<bits<7> funct7, bits<3> fu
: RVInstR<funct7, funct3, OPC_OP_32, (outs GPR:$rd),
(ins GPR:$rs1, GPR:$rs2), opcodestr, "$rd, $rs1, $rs2">;
+let hasSideEffects = 1, mayLoad = 0, mayStore = 0 in
+class Priv<string opcodestr, bits<7> funct7>
+ : RVInstR<funct7, 0b000, OPC_SYSTEM, (outs), (ins GPR:$rs1, GPR:$rs2),
+ opcodestr, "">;
+
//===----------------------------------------------------------------------===//
// Instructions
//===----------------------------------------------------------------------===//
@@ -334,6 +339,43 @@ def SRAW : ALUW_rr<0b0100000, 0b101, "s
} // Predicates = [IsRV64]
//===----------------------------------------------------------------------===//
+// Privileged instructions
+//===----------------------------------------------------------------------===//
+
+let isBarrier = 1, isReturn = 1, isTerminator = 1 in {
+def URET : Priv<"uret", 0b0000000> {
+ let rd = 0;
+ let rs1 = 0;
+ let rs2 = 0b00010;
+}
+
+def SRET : Priv<"sret", 0b0001000> {
+ let rd = 0;
+ let rs1 = 0;
+ let rs2 = 0b00010;
+}
+
+def MRET : Priv<"mret", 0b0011000> {
+ let rd = 0;
+ let rs1 = 0;
+ let rs2 = 0b00010;
+}
+} // isBarrier = 1, isReturn = 1, isTerminator = 1
+
+def WFI : Priv<"wfi", 0b0001000> {
+ let rd = 0;
+ let rs1 = 0;
+ let rs2 = 0b00101;
+}
+
+let hasSideEffects = 1, mayLoad = 0, mayStore = 0 in
+def SFENCE_VMA : RVInstR<0b0001001, 0b000, OPC_SYSTEM, (outs),
+ (ins GPR:$rs1, GPR:$rs2),
+ "sfence.vma", "$rs1, $rs2"> {
+ let rd = 0;
+}
+
+//===----------------------------------------------------------------------===//
// Pseudo-instructions and codegen patterns
//
// Naming convention: For 'generic' pattern classes, we use the naming
Added: llvm/trunk/test/MC/RISCV/priv-invalid.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/RISCV/priv-invalid.s?rev=320484&view=auto
==============================================================================
--- llvm/trunk/test/MC/RISCV/priv-invalid.s (added)
+++ llvm/trunk/test/MC/RISCV/priv-invalid.s Tue Dec 12 07:17:45 2017
@@ -0,0 +1,7 @@
+# RUN: not llvm-mc -triple riscv32 < %s 2>&1 | FileCheck %s
+
+mret 0x10 # CHECK: :[[@LINE]]:6: error: invalid operand for instruction
+
+sfence.vma zero # CHECK: :[[@LINE]]:1: error: too few operands for instruction
+
+sfence.vma a0, 0x10 # CHECK: :[[@LINE]]:16: error: invalid operand for instruction
Added: llvm/trunk/test/MC/RISCV/priv-valid.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/RISCV/priv-valid.s?rev=320484&view=auto
==============================================================================
--- llvm/trunk/test/MC/RISCV/priv-valid.s (added)
+++ llvm/trunk/test/MC/RISCV/priv-valid.s Tue Dec 12 07:17:45 2017
@@ -0,0 +1,32 @@
+# RUN: llvm-mc %s -triple=riscv32 -show-encoding \
+# RUN: | FileCheck -check-prefixes=CHECK,CHECK-INST %s
+# RUN: llvm-mc %s -triple=riscv64 -show-encoding \
+# RUN: | FileCheck -check-prefixes=CHECK,CHECK-INST %s
+# RUN: llvm-mc -filetype=obj -triple riscv32 < %s \
+# RUN: | llvm-objdump -d - | FileCheck -check-prefix=CHECK-INST %s
+# RUN: llvm-mc -filetype=obj -triple riscv64 < %s \
+# RUN: | llvm-objdump -d - | FileCheck -check-prefix=CHECK-INST %s
+
+# CHECK-INST: uret
+# CHECK: encoding: [0x73,0x00,0x20,0x00]
+uret
+
+# CHECK-INST: sret
+# CHECK: encoding: [0x73,0x00,0x20,0x10]
+sret
+
+# CHECK-INST: mret
+# CHECK: encoding: [0x73,0x00,0x20,0x30]
+mret
+
+# CHECK-INST: wfi
+# CHECK: encoding: [0x73,0x00,0x50,0x10]
+wfi
+
+# CHECK-INST: sfence.vma zero, zero
+# CHECK: encoding: [0x73,0x00,0x00,0x12]
+sfence.vma zero, zero
+
+# CHECK-INST: sfence.vma a0, a1
+# CHECK: encoding: [0x73,0x00,0xb5,0x12]
+sfence.vma a0, a1
More information about the llvm-commits
mailing list