diff --git a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp --- a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp +++ b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp @@ -555,41 +555,19 @@ return (isRV64() && isUInt<5>(Imm)) || isUInt<4>(Imm); } - bool isUImm2() const { + template 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(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 --- a/llvm/lib/Target/RISCV/RISCVInstrInfo.cpp +++ b/llvm/lib/Target/RISCV/RISCVInstrInfo.cpp @@ -1058,30 +1058,23 @@ 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(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);