[llvm] 6c6b3e3 - RISCV: add a few deprecated aliases for CSRs

Saleem Abdulrasool via llvm-commits llvm-commits at lists.llvm.org
Fri May 21 13:55:18 PDT 2021


Author: Saleem Abdulrasool
Date: 2021-05-21T13:52:58-07:00
New Revision: 6c6b3e3afe7cbf43d6ab2aa780367e6942f1b6b4

URL: https://github.com/llvm/llvm-project/commit/6c6b3e3afe7cbf43d6ab2aa780367e6942f1b6b4
DIFF: https://github.com/llvm/llvm-project/commit/6c6b3e3afe7cbf43d6ab2aa780367e6942f1b6b4.diff

LOG: RISCV: add a few deprecated aliases for CSRs

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

Added: 
    llvm/test/MC/RISCV/deprecated-csr-names.s

Modified: 
    llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
    llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h
    llvm/lib/Target/RISCV/RISCVSystemOperands.td

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
index 5bcded44df2e8..6be4373e5fc58 100644
--- a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
+++ b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
@@ -1312,6 +1312,11 @@ RISCVAsmParser::parseCSRSystemRegister(OperandVector &Operands) {
     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())) {

diff  --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h
index 123cf298e5bb7..d65590e8d25d8 100644
--- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h
+++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h
@@ -242,8 +242,9 @@ inline static bool isValidRoundingMode(unsigned Mode) {
 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;

diff  --git a/llvm/lib/Target/RISCV/RISCVSystemOperands.td b/llvm/lib/Target/RISCV/RISCVSystemOperands.td
index dd86bb2ca756a..a561772b650b3 100644
--- a/llvm/lib/Target/RISCV/RISCVSystemOperands.td
+++ b/llvm/lib/Target/RISCV/RISCVSystemOperands.td
@@ -19,9 +19,13 @@ include "llvm/TableGen/SearchableTable.td"
 
 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.
@@ -38,7 +42,10 @@ class SysReg<string name, bits<12> op> {
 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";
@@ -54,6 +61,11 @@ def lookupSysRegByAltName : SearchIndex {
   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.
@@ -71,6 +83,7 @@ def : SysReg<"utvec", 0x005>;
 def : SysReg<"uscratch", 0x040>;
 def : SysReg<"uepc", 0x041>;
 def : SysReg<"ucause", 0x042>;
+let DeprecatedName = "ubadaddr" in
 def : SysReg<"utval", 0x043>;
 def : SysReg<"uip", 0x044>;
 
@@ -171,12 +184,14 @@ def : SysReg<"scounteren", 0x106>;
 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>;
 
 //===-----------------------------
@@ -205,6 +220,7 @@ def : SysReg<"mcounteren", 0x306>;
 def : SysReg<"mscratch", 0x340>;
 def : SysReg<"mepc", 0x341>;
 def : SysReg<"mcause", 0x342>;
+let DeprecatedName = "mbadaddr" in
 def : SysReg<"mtval", 0x343>;
 def : SysReg<"mip", 0x344>;
 

diff  --git a/llvm/test/MC/RISCV/deprecated-csr-names.s b/llvm/test/MC/RISCV/deprecated-csr-names.s
new file mode 100644
index 0000000000000..f3c475d54699f
--- /dev/null
+++ b/llvm/test/MC/RISCV/deprecated-csr-names.s
@@ -0,0 +1,77 @@
+# 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'


        


More information about the llvm-commits mailing list