-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[RISCV] Add OperandType to frmarg and rtzarg. #114142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Teach RISCVInstrInfo::verifyInstruction to validate them. This is partially extracted from llvm#89047, but that did not include the verification.
|
@llvm/pr-subscribers-backend-risc-v Author: Craig Topper (topperc) ChangesTeach RISCVInstrInfo::verifyInstruction to validate them. This is partially extracted from #89047, but that did not include the verification. Full diff: https://github.com/llvm/llvm-project/pull/114142.diff 4 Files Affected:
diff --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h
index d82f78498418da..e18329c3d2dd49 100644
--- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h
+++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h
@@ -330,7 +330,12 @@ enum OperandType : unsigned {
OPERAND_RVKRNUM_1_10,
OPERAND_RVKRNUM_2_14,
OPERAND_SPIMM,
- OPERAND_LAST_RISCV_IMM = OPERAND_SPIMM,
+ // Operand is a 3-bit rounding mode, '111' indicates FRM register.
+ // Represents 'frm' argument passing to floating-point operations.
+ OPERAND_FRMARG,
+ // Operand is a 3-bit rounding mode where only RTZ is valid.
+ OPERAND_RTZARG,
+ OPERAND_LAST_RISCV_IMM = OPERAND_RTZARG,
// Operand is either a register or uimm5, this is used by V extension pseudo
// instructions to represent a value that be passed as AVL to either vsetvli
// or vsetivli.
diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfo.cpp b/llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
index a3963fadf3e417..20e531657eb286 100644
--- a/llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
+++ b/llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
@@ -2536,6 +2536,12 @@ bool RISCVInstrInfo::verifyInstruction(const MachineInstr &MI,
case RISCVOp::OPERAND_SPIMM:
Ok = (Imm & 0xf) == 0;
break;
+ case RISCVOp::OPERAND_FRMARG:
+ Ok = RISCVFPRndMode::isValidRoundingMode(Imm);
+ break;
+ case RISCVOp::OPERAND_RTZARG:
+ Ok = Imm == RISCVFPRndMode::RTZ;
+ break;
}
if (!Ok) {
ErrInfo = "Invalid immediate";
diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfoF.td b/llvm/lib/Target/RISCV/RISCVInstrInfoF.td
index a134f37c774954..da3f207a2faf72 100644
--- a/llvm/lib/Target/RISCV/RISCVInstrInfoF.td
+++ b/llvm/lib/Target/RISCV/RISCVInstrInfoF.td
@@ -134,6 +134,8 @@ def frmarg : Operand<XLenVT> {
let ParserMatchClass = FRMArg;
let PrintMethod = "printFRMArg";
let DecoderMethod = "decodeFRMArg";
+ let OperandType = "OPERAND_FRMARG";
+ let OperandNamespace = "RISCVOp";
}
// Variants of the rounding mode operand that default to 'rne'. This is used
@@ -154,6 +156,8 @@ def frmarglegacy : Operand<XLenVT> {
let ParserMatchClass = FRMArgLegacy;
let PrintMethod = "printFRMArgLegacy";
let DecoderMethod = "decodeFRMArg";
+ let OperandType = "OPERAND_FRMARG";
+ let OperandNamespace = "RISCVOp";
}
//===----------------------------------------------------------------------===//
diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfoZfa.td b/llvm/lib/Target/RISCV/RISCVInstrInfoZfa.td
index f62a7e1221122b..2bdcfd21270e90 100644
--- a/llvm/lib/Target/RISCV/RISCVInstrInfoZfa.td
+++ b/llvm/lib/Target/RISCV/RISCVInstrInfoZfa.td
@@ -48,6 +48,8 @@ def rtzarg : Operand<XLenVT> {
let ParserMatchClass = RTZArg;
let PrintMethod = "printFRMArg";
let DecoderMethod = "decodeRTZArg";
+ let OperandType = "OPERAND_RTZARG";
+ let OperandNamespace = "RISCVOp";
}
//===----------------------------------------------------------------------===//
|
lenary
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
mshockwave
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Teach RISCVInstrInfo::verifyInstruction to validate them. This is partially extracted from llvm#89047, but that did not include the verification.
Teach RISCVInstrInfo::verifyInstruction to validate them.
This is partially extracted from #89047, but that did not include the verification.