Skip to content

Commit 1401703

Browse files
authored
[RISCV] Add Enum for CSR encodings. (#121674)
This allows us to use them in C++ code without needing to do a table lookup.
1 parent fe42e63 commit 1401703

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,7 @@ struct SysReg {
480480
}
481481
};
482482

483+
#define GET_SysRegEncodings_DECL
483484
#define GET_SysRegsList_DECL
484485
#include "RISCVGenSearchableTables.inc"
485486
} // end namespace RISCVSysReg

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12663,8 +12663,7 @@ SDValue RISCVTargetLowering::lowerGET_ROUNDING(SDValue Op,
1266312663
const MVT XLenVT = Subtarget.getXLenVT();
1266412664
SDLoc DL(Op);
1266512665
SDValue Chain = Op->getOperand(0);
12666-
SDValue SysRegNo = DAG.getTargetConstant(
12667-
RISCVSysReg::lookupSysRegByName("FRM")->Encoding, DL, XLenVT);
12666+
SDValue SysRegNo = DAG.getTargetConstant(RISCVSysReg::frm, DL, XLenVT);
1266812667
SDVTList VTs = DAG.getVTList(XLenVT, MVT::Other);
1266912668
SDValue RM = DAG.getNode(RISCVISD::READ_CSR, DL, VTs, Chain, SysRegNo);
1267012669

@@ -12695,8 +12694,7 @@ SDValue RISCVTargetLowering::lowerSET_ROUNDING(SDValue Op,
1269512694
SDLoc DL(Op);
1269612695
SDValue Chain = Op->getOperand(0);
1269712696
SDValue RMValue = Op->getOperand(1);
12698-
SDValue SysRegNo = DAG.getTargetConstant(
12699-
RISCVSysReg::lookupSysRegByName("FRM")->Encoding, DL, XLenVT);
12697+
SDValue SysRegNo = DAG.getTargetConstant(RISCVSysReg::frm, DL, XLenVT);
1270012698

1270112699
// Encoding used for rounding mode in RISC-V differs from that used in
1270212700
// FLT_ROUNDS. To convert it the C rounding mode is used as an index in
@@ -12899,15 +12897,11 @@ void RISCVTargetLowering::ReplaceNodeResults(SDNode *N,
1289912897
SDValue LoCounter, HiCounter;
1290012898
MVT XLenVT = Subtarget.getXLenVT();
1290112899
if (N->getOpcode() == ISD::READCYCLECOUNTER) {
12902-
LoCounter = DAG.getTargetConstant(
12903-
RISCVSysReg::lookupSysRegByName("CYCLE")->Encoding, DL, XLenVT);
12904-
HiCounter = DAG.getTargetConstant(
12905-
RISCVSysReg::lookupSysRegByName("CYCLEH")->Encoding, DL, XLenVT);
12900+
LoCounter = DAG.getTargetConstant(RISCVSysReg::cycle, DL, XLenVT);
12901+
HiCounter = DAG.getTargetConstant(RISCVSysReg::cycleh, DL, XLenVT);
1290612902
} else {
12907-
LoCounter = DAG.getTargetConstant(
12908-
RISCVSysReg::lookupSysRegByName("TIME")->Encoding, DL, XLenVT);
12909-
HiCounter = DAG.getTargetConstant(
12910-
RISCVSysReg::lookupSysRegByName("TIMEH")->Encoding, DL, XLenVT);
12903+
LoCounter = DAG.getTargetConstant(RISCVSysReg::time, DL, XLenVT);
12904+
HiCounter = DAG.getTargetConstant(RISCVSysReg::timeh, DL, XLenVT);
1291112905
}
1291212906
SDVTList VTs = DAG.getVTList(MVT::i32, MVT::i32, MVT::Other);
1291312907
SDValue RCW = DAG.getNode(RISCVISD::READ_COUNTER_WIDE, DL, VTs,

llvm/lib/Target/RISCV/RISCVSystemOperands.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ def SysRegsList : GenericTable {
4848
let PrimaryKeyReturnRange = true;
4949
}
5050

51+
def SysRegEncodings : GenericEnum {
52+
let FilterClass = "SysReg";
53+
let NameField = "Name";
54+
let ValueField = "Encoding";
55+
}
56+
5157
def lookupSysRegByName : SearchIndex {
5258
let Table = SysRegsList;
5359
let Key = [ "Name" ];

0 commit comments

Comments
 (0)