[llvm] 529f05c - [RISCV][MC] Fold UIMM related code
Shao-Ce SUN via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 24 19:50:56 PDT 2022
Author: Shao-Ce SUN
Date: 2022-06-25T10:50:50+08:00
New Revision: 529f05cdbbe9a153a970fc494dc4406ae1dafde5
URL: https://github.com/llvm/llvm-project/commit/529f05cdbbe9a153a970fc494dc4406ae1dafde5
DIFF: https://github.com/llvm/llvm-project/commit/529f05cdbbe9a153a970fc494dc4406ae1dafde5.diff
LOG: [RISCV][MC] Fold UIMM related code
Reviewed By: craig.topper
Differential Revision: https://reviews.llvm.org/D128495
Added:
Modified:
llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
index f8e3e67a5ec57..9c59c7bc57554 100644
--- a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
+++ b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
@@ -555,41 +555,19 @@ struct RISCVOperand : public MCParsedAsmOperand {
return (isRV64() && isUInt<5>(Imm)) || isUInt<4>(Imm);
}
- bool isUImm2() const {
+ template <unsigned N> bool IsUImm() const {
int64_t Imm;
RISCVMCExpr::VariantKind VK = RISCVMCExpr::VK_RISCV_None;
if (!isImm())
return false;
bool IsConstantImm = evaluateConstantImm(getImm(), Imm, VK);
- return IsConstantImm && isUInt<2>(Imm) && VK == RISCVMCExpr::VK_RISCV_None;
+ return IsConstantImm && isUInt<N>(Imm) && VK == RISCVMCExpr::VK_RISCV_None;
}
- bool isUImm3() const {
- int64_t Imm;
- RISCVMCExpr::VariantKind VK = RISCVMCExpr::VK_RISCV_None;
- if (!isImm())
- return false;
- bool IsConstantImm = evaluateConstantImm(getImm(), Imm, VK);
- return IsConstantImm && isUInt<3>(Imm) && VK == RISCVMCExpr::VK_RISCV_None;
- }
-
- bool isUImm5() const {
- int64_t Imm;
- RISCVMCExpr::VariantKind VK = RISCVMCExpr::VK_RISCV_None;
- if (!isImm())
- return false;
- bool IsConstantImm = evaluateConstantImm(getImm(), Imm, VK);
- return IsConstantImm && isUInt<5>(Imm) && VK == RISCVMCExpr::VK_RISCV_None;
- }
-
- bool isUImm7() const {
- int64_t Imm;
- RISCVMCExpr::VariantKind VK = RISCVMCExpr::VK_RISCV_None;
- if (!isImm())
- return false;
- bool IsConstantImm = evaluateConstantImm(getImm(), Imm, VK);
- return IsConstantImm && isUInt<7>(Imm) && VK == RISCVMCExpr::VK_RISCV_None;
- }
+ bool isUImm2() { return IsUImm<2>(); }
+ bool isUImm3() { return IsUImm<3>(); }
+ bool isUImm5() { return IsUImm<5>(); }
+ bool isUImm7() { return IsUImm<7>(); }
bool isRnumArg() const {
int64_t Imm;
diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfo.cpp b/llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
index 3f9e9dfc2fb73..605fc616891dd 100644
--- a/llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
+++ b/llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
@@ -1058,30 +1058,23 @@ bool RISCVInstrInfo::verifyInstruction(const MachineInstr &MI,
switch (OpType) {
default:
llvm_unreachable("Unexpected operand type");
- case RISCVOp::OPERAND_UIMM2:
- Ok = isUInt<2>(Imm);
- break;
- case RISCVOp::OPERAND_UIMM3:
- Ok = isUInt<3>(Imm);
- break;
- case RISCVOp::OPERAND_UIMM4:
- Ok = isUInt<4>(Imm);
- break;
- case RISCVOp::OPERAND_UIMM5:
- Ok = isUInt<5>(Imm);
- break;
- case RISCVOp::OPERAND_UIMM7:
- Ok = isUInt<7>(Imm);
- break;
- case RISCVOp::OPERAND_UIMM12:
- Ok = isUInt<12>(Imm);
- break;
+
+ // clang-format off
+#define CASE_OPERAND_UIMM(NUM) \
+ case RISCVOp::OPERAND_UIMM##NUM: \
+ Ok = isUInt<NUM>(Imm); \
+ break;
+ CASE_OPERAND_UIMM(2)
+ CASE_OPERAND_UIMM(3)
+ CASE_OPERAND_UIMM(4)
+ CASE_OPERAND_UIMM(5)
+ CASE_OPERAND_UIMM(7)
+ CASE_OPERAND_UIMM(12)
+ CASE_OPERAND_UIMM(20)
+ // clang-format on
case RISCVOp::OPERAND_SIMM12:
Ok = isInt<12>(Imm);
break;
- case RISCVOp::OPERAND_UIMM20:
- Ok = isUInt<20>(Imm);
- break;
case RISCVOp::OPERAND_UIMMLOG2XLEN:
if (STI.getTargetTriple().isArch64Bit())
Ok = isUInt<6>(Imm);
More information about the llvm-commits
mailing list