[llvm] [RISCV] Merge decodeUImmOperand and decodeUImmOperandGE. NFC (PR #223925)
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 15 23:49:28 PDT 2026
https://github.com/topperc created https://github.com/llvm/llvm-project/pull/223925
Add the LowerBound template argument to decodeUImmOperand with a default value of 0.
Similar for decodeUImmPlus1Operand and decodeUImmPlus1OperandGE, but default the LowerBound to 1.
>From 0d3687ca2299ba7d324c7cec94c273a1c1b387d3 Mon Sep 17 00:00:00 2001
From: Craig Topper <craig.topper at sifive.com>
Date: Tue, 15 Sep 2026 23:46:20 -0700
Subject: [PATCH] [RISCV] Merge decodeUImmOperand and decodeUImmOperandGE. NFC
Add the LowerBound template argument to decodeUImmOperand with
a default value of 0.
Similar for decodeUImmPlus1Operand and decodeUImmPlus1OperandGE,
but default the LowerBound to 1.
---
.../RISCV/Disassembler/RISCVDisassembler.cpp | 30 ++++---------------
llvm/lib/Target/RISCV/RISCVInstrInfoXqci.td | 4 +--
llvm/lib/Target/RISCV/RISCVInstrInfoZc.td | 2 +-
3 files changed, 9 insertions(+), 27 deletions(-)
diff --git a/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp b/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
index 90b37950a906e..115721a176297 100644
--- a/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
+++ b/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
@@ -283,20 +283,11 @@ static DecodeStatus decodeImmFourOperand(MCInst &Inst,
return MCDisassembler::Success;
}
-template <unsigned N>
+template <unsigned N, unsigned LowerBound = 0>
static DecodeStatus decodeUImmOperand(MCInst &Inst, uint32_t Imm,
int64_t Address,
const MCDisassembler *Decoder) {
assert(isUInt<N>(Imm) && "Invalid immediate");
- Inst.addOperand(MCOperand::createImm(Imm));
- return MCDisassembler::Success;
-}
-
-template <unsigned Width, unsigned LowerBound>
-static DecodeStatus decodeUImmOperandGE(MCInst &Inst, uint32_t Imm,
- int64_t Address,
- const MCDisassembler *Decoder) {
- assert(isUInt<Width>(Imm) && "Invalid immediate");
if (Imm < LowerBound)
return MCDisassembler::Fail;
@@ -305,19 +296,6 @@ static DecodeStatus decodeUImmOperandGE(MCInst &Inst, uint32_t Imm,
return MCDisassembler::Success;
}
-template <unsigned Width, unsigned LowerBound>
-static DecodeStatus decodeUImmPlus1OperandGE(MCInst &Inst, uint32_t Imm,
- int64_t Address,
- const MCDisassembler *Decoder) {
- assert(isUInt<Width>(Imm) && "Invalid immediate");
-
- if ((Imm + 1) < LowerBound)
- return MCDisassembler::Fail;
-
- Inst.addOperand(MCOperand::createImm(Imm + 1));
- return MCDisassembler::Success;
-}
-
static DecodeStatus decodeUImmSlistOperand(MCInst &Inst, uint32_t Imm,
int64_t Address,
const MCDisassembler *Decoder) {
@@ -371,11 +349,15 @@ decodeUImmLog2XLenNonZeroOperand(MCInst &Inst, uint32_t Imm, int64_t Address,
return decodeUImmLog2XLenOperand(Inst, Imm, Address, Decoder);
}
-template <unsigned N>
+template <unsigned N, unsigned LowerBound = 1>
static DecodeStatus decodeUImmPlus1Operand(MCInst &Inst, uint32_t Imm,
int64_t Address,
const MCDisassembler *Decoder) {
assert(isUInt<N>(Imm) && "Invalid immediate");
+
+ if ((Imm + 1) < LowerBound)
+ return MCDisassembler::Fail;
+
Inst.addOperand(MCOperand::createImm(Imm + 1));
return MCDisassembler::Success;
}
diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfoXqci.td b/llvm/lib/Target/RISCV/RISCVInstrInfoXqci.td
index aa0a64110e2ea..643d04d1da878 100644
--- a/llvm/lib/Target/RISCV/RISCVInstrInfoXqci.td
+++ b/llvm/lib/Target/RISCV/RISCVInstrInfoXqci.td
@@ -55,7 +55,7 @@ def tuimm5nonzero : TImmLeaf<XLenVT, [{return (Imm != 0) && isUInt<5>(Imm);}]>;
def uimm5gt3 : RISCVOp<XLenVT>, ImmLeaf<XLenVT,
[{return (Imm > 3) && isUInt<5>(Imm);}]> {
let ParserMatchClass = UImmAsmOperand<5, "GT3">;
- let DecoderMethod = "decodeUImmOperandGE<5, 4>";
+ let DecoderMethod = "decodeUImmOperand<5, 4>";
let OperandType = "OPERAND_UIMM5_GT3";
}
@@ -65,7 +65,7 @@ def uimm5ge6_plus1 : RISCVOp<XLenVT>, ImmLeaf<XLenVT,
[{return Imm >= 6 && Imm <= 32;}]> {
let ParserMatchClass = UImmAsmOperand<5, "GE6Plus1">;
let EncoderMethod = "getImmOpValueMinus1";
- let DecoderMethod = "decodeUImmPlus1OperandGE<5,6>";
+ let DecoderMethod = "decodeUImmPlus1Operand<5, 6>";
let OperandType = "OPERAND_UIMM5_GE6_PLUS1";
let MCOperandPredicate = [{
int64_t Imm;
diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfoZc.td b/llvm/lib/Target/RISCV/RISCVInstrInfoZc.td
index 0fa11b323a9f7..20cb65c9083ab 100644
--- a/llvm/lib/Target/RISCV/RISCVInstrInfoZc.td
+++ b/llvm/lib/Target/RISCV/RISCVInstrInfoZc.td
@@ -22,7 +22,7 @@ def uimm2_lsb0_optional : OptionalUImmLsbZeroOp<2, 1>;
def uimm8ge32 : RISCVOp {
let ParserMatchClass = UImmAsmOperand<8, "GE32">;
- let DecoderMethod = "decodeUImmOperandGE<8, 32>";
+ let DecoderMethod = "decodeUImmOperand<8, 32>";
let OperandType = "OPERAND_UIMM8_GE32";
}
More information about the llvm-commits
mailing list