Skip to content

Commit c76d337

Browse files
toppercNoumanAmir657
authored andcommitted
[RISCV] Add OperandType to frmarg and rtzarg. (llvm#114142)
Teach RISCVInstrInfo::verifyInstruction to validate them. This is partially extracted from llvm#89047, but that did not include the verification.
1 parent d6b76a1 commit c76d337

File tree

4 files changed

+18
-1
lines changed

4 files changed

+18
-1
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,12 @@ enum OperandType : unsigned {
330330
OPERAND_RVKRNUM_1_10,
331331
OPERAND_RVKRNUM_2_14,
332332
OPERAND_SPIMM,
333-
OPERAND_LAST_RISCV_IMM = OPERAND_SPIMM,
333+
// Operand is a 3-bit rounding mode, '111' indicates FRM register.
334+
// Represents 'frm' argument passing to floating-point operations.
335+
OPERAND_FRMARG,
336+
// Operand is a 3-bit rounding mode where only RTZ is valid.
337+
OPERAND_RTZARG,
338+
OPERAND_LAST_RISCV_IMM = OPERAND_RTZARG,
334339
// Operand is either a register or uimm5, this is used by V extension pseudo
335340
// instructions to represent a value that be passed as AVL to either vsetvli
336341
// or vsetivli.

llvm/lib/Target/RISCV/RISCVInstrInfo.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2536,6 +2536,12 @@ bool RISCVInstrInfo::verifyInstruction(const MachineInstr &MI,
25362536
case RISCVOp::OPERAND_SPIMM:
25372537
Ok = (Imm & 0xf) == 0;
25382538
break;
2539+
case RISCVOp::OPERAND_FRMARG:
2540+
Ok = RISCVFPRndMode::isValidRoundingMode(Imm);
2541+
break;
2542+
case RISCVOp::OPERAND_RTZARG:
2543+
Ok = Imm == RISCVFPRndMode::RTZ;
2544+
break;
25392545
}
25402546
if (!Ok) {
25412547
ErrInfo = "Invalid immediate";

llvm/lib/Target/RISCV/RISCVInstrInfoF.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ def frmarg : Operand<XLenVT> {
134134
let ParserMatchClass = FRMArg;
135135
let PrintMethod = "printFRMArg";
136136
let DecoderMethod = "decodeFRMArg";
137+
let OperandType = "OPERAND_FRMARG";
138+
let OperandNamespace = "RISCVOp";
137139
}
138140

139141
// Variants of the rounding mode operand that default to 'rne'. This is used
@@ -154,6 +156,8 @@ def frmarglegacy : Operand<XLenVT> {
154156
let ParserMatchClass = FRMArgLegacy;
155157
let PrintMethod = "printFRMArgLegacy";
156158
let DecoderMethod = "decodeFRMArg";
159+
let OperandType = "OPERAND_FRMARG";
160+
let OperandNamespace = "RISCVOp";
157161
}
158162

159163
//===----------------------------------------------------------------------===//

llvm/lib/Target/RISCV/RISCVInstrInfoZfa.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ def rtzarg : Operand<XLenVT> {
4848
let ParserMatchClass = RTZArg;
4949
let PrintMethod = "printFRMArg";
5050
let DecoderMethod = "decodeRTZArg";
51+
let OperandType = "OPERAND_RTZARG";
52+
let OperandNamespace = "RISCVOp";
5153
}
5254

5355
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)