This adds the {s,u,m}badaddr CSR aliases as well as the sptbr alias.
These are for compatibility with binutils. Furthermore, these are used
by the RISC-V Proxy Kernel and are required to enable building the Proxy
Kernel with the LLVM IAS.
The aliases here are deprecated. These are being introduced in order to
provide a compatibility story for the existing GNU toolchain, which
still supports the deprecated spelling in the assembler. However, in
order to encourage the migration of existing coding, we provide warnings
indicating that the aliased CSRs are deprecated and should be replaced.
Differential Revision: https://reviews.llvm.org/D101919
Reviewed By: Craig Topper
auto SysReg = RISCVSysReg::lookupSysRegByName(Identifier);
if (!SysReg)
SysReg = RISCVSysReg::lookupSysRegByAltName(Identifier);
+ if (!SysReg)
+ if ((SysReg = RISCVSysReg::lookupSysRegByDeprecatedName(Identifier)))
+ Warning(S, "'" + Identifier + "' is a deprecated alias for '" +
+ SysReg->Name + "'");
+
// Accept a named Sys Reg if the required features are present.
if (SysReg) {
if (!SysReg->haveRequiredFeatures(getSTI().getFeatureBits())) {
namespace RISCVSysReg {
struct SysReg {
const char *Name;
- unsigned Encoding;
const char *AltName;
+ const char *DeprecatedName;
+ unsigned Encoding;
// FIXME: add these additional fields when needed.
// Privilege Access: Read, Write, Read-Only.
// unsigned ReadWrite;
class SysReg<string name, bits<12> op> {
string Name = name;
- bits<12> Encoding = op;
// A maximum of one alias is supported right now.
string AltName = name;
+ // A maximum of one deprecated name is supported right now. Unlike the
+ // `AltName` alias, a `DeprecatedName` generates a diagnostic when the name is
+ // used to encourage software to migrate away from the name.
+ string DeprecatedName = "";
+ bits<12> Encoding = op;
// FIXME: add these additional fields when needed.
// Privilege Access: Read and Write = 0, 1, 2; Read-Only = 3.
// Privilege Mode: User = 0, System = 1 or Machine = 3.
def SysRegsList : GenericTable {
let FilterClass = "SysReg";
// FIXME: add "ReadWrite", "Mode", "Extra", "Number" fields when needed.
- let Fields = [ "Name", "Encoding", "AltName", "FeaturesRequired", "isRV32Only" ];
+ let Fields = [
+ "Name", "AltName", "DeprecatedName", "Encoding", "FeaturesRequired",
+ "isRV32Only",
+ ];
let PrimaryKey = [ "Encoding" ];
let PrimaryKeyName = "lookupSysRegByEncoding";
let Key = [ "AltName" ];
}
+def lookupSysRegByDeprecatedName : SearchIndex {
+ let Table = SysRegsList;
+ let Key = [ "DeprecatedName" ];
+}
+
// The following CSR encodings match those given in Tables 2.2,
// 2.3, 2.4 and 2.5 in the RISC-V Instruction Set Manual
// Volume II: Privileged Architecture.
def : SysReg<"uscratch", 0x040>;
def : SysReg<"uepc", 0x041>;
def : SysReg<"ucause", 0x042>;
+let DeprecatedName = "ubadaddr" in
def : SysReg<"utval", 0x043>;
def : SysReg<"uip", 0x044>;
def : SysReg<"sscratch", 0x140>;
def : SysReg<"sepc", 0x141>;
def : SysReg<"scause", 0x142>;
+let DeprecatedName = "sbadaddr" in
def : SysReg<"stval", 0x143>;
def : SysReg<"sip", 0x144>;
//===-------------------------------------
// Supervisor Protection and Translation
//===-------------------------------------
+let DeprecatedName = "sptbr" in
def : SysReg<"satp", 0x180>;
//===-----------------------------
def : SysReg<"mscratch", 0x340>;
def : SysReg<"mepc", 0x341>;
def : SysReg<"mcause", 0x342>;
+let DeprecatedName = "mbadaddr" in
def : SysReg<"mtval", 0x343>;
def : SysReg<"mip", 0x344>;
--- /dev/null
+# RUN: llvm-mc -triple riscv32 -riscv-no-aliases -show-encoding %s \
+# RUN: | FileCheck -check-prefixes CHECK-INST,CHECK-ENC %s
+# RUN: llvm-mc -filetype obj -triple riscv32 %s \
+# RUN: | llvm-objdump -d - \
+# RUN: | FileCheck -check-prefix=CHECK-INST-ALIAS %s
+
+# RUN: llvm-mc -triple riscv64 -riscv-no-aliases -show-encoding %s \
+# RUN: | FileCheck -check-prefixes CHECK-INST,CHECK-ENC %s
+# RUN: llvm-mc -filetype obj -triple riscv64 %s \
+# RUN: | llvm-objdump -d - \
+# RUN: | FileCheck -check-prefix=CHECK-INST-ALIAS %s
+
+# RUN: llvm-mc -triple riscv32 %s 2>&1 | FileCheck -check-prefix CHECK-WARN %s
+
+# sbadaddr
+# name
+# CHECK-INST: csrrw zero, stval, zero
+# CHECK-ENC: encoding: [0x73,0x10,0x30,0x14]
+# CHECK-INST-ALIAS: csrw stval, zero
+# uimm12
+# CHECK-INST: csrrw zero, stval, zero
+# CHECK-ENC: encoding: [0x73,0x10,0x30,0x14]
+# CHECK-INST-ALIAS: csrw stval, zero
+# name
+csrw sbadaddr, zero
+# uimm12
+csrrw zero, 0x143, zero
+
+# CHECK-WARN: warning: 'sbadaddr' is a deprecated alias for 'stval'
+
+# mbadaddr
+# name
+# CHECK-INST: csrrw zero, mtval, zero
+# CHECK-ENC: encoding: [0x73,0x10,0x30,0x34]
+# CHECK-INST-ALIAS: csrw mtval, zero
+# uimm12
+# CHECK-INST: csrrw zero, mtval, zero
+# CHECK-ENC: encoding: [0x73,0x10,0x30,0x34]
+# CHECK-INST-ALIAS: csrw mtval, zero
+# name
+csrw mbadaddr, zero
+# uimm12
+csrrw zero, 0x343, zero
+
+# CHECK-WARN: warning: 'mbadaddr' is a deprecated alias for 'mtval'
+
+# ubadaddr
+# name
+# CHECK-INST: csrrw zero, utval, zero
+# CHECK-ENC: encoding: [0x73,0x10,0x30,0x04]
+# CHECK-INST-ALIAS: csrw utval, zero
+# uimm12
+# CHECK-INST: csrrw zero, utval, zero
+# CHECK-ENC: encoding: [0x73,0x10,0x30,0x04]
+# CHECK-INST-ALIAS: csrw utval, zero
+# name
+csrw ubadaddr, zero
+# uimm12
+csrrw zero, 0x043, zero
+
+# CHECK-WARN: warning: 'ubadaddr' is a deprecated alias for 'utval'
+
+# sptbr
+# name
+# CHECK-INST: csrrw zero, satp, zero
+# CHECK-ENC: encoding: [0x73,0x10,0x00,0x18]
+# CHECK-INST-ALIAS: csrw satp, zero
+# uimm12
+# CHECK-INST: csrrw zero, satp, zero
+# CHECK-ENC: encoding: [0x73,0x10,0x00,0x18]
+# CHECK-INST-ALIAS: csrw satp, zero
+# name
+csrw sptbr, zero
+# uimm12
+csrrw zero, 0x180, zero
+
+# CHECK-WARN: warning: 'sptbr' is a deprecated alias for 'satp'