aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
diff options
context:
space:
mode:
authorCraig Topper <craig.topper@sifive.com>2024-11-08 09:12:25 -0800
committerGitHub <noreply@github.com>2024-11-08 09:12:25 -0800
commitbde3d4a62e714f179c6e859758582d5ef9efa5f8 (patch)
tree3ee672ac595328efe2ecded981b0771c7fff74f3 /llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
parent92e0fb0c944254312d7b9c6ca64a026643617f60 (diff)
downloadllvm-bde3d4a62e714f179c6e859758582d5ef9efa5f8.zip
llvm-bde3d4a62e714f179c6e859758582d5ef9efa5f8.tar.gz
llvm-bde3d4a62e714f179c6e859758582d5ef9efa5f8.tar.bz2
[RISCV] Only allow 5 bit shift amounts in disassembler for RV32. (#115432)
Fixes 2 old TODOs
Diffstat (limited to 'llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp')
-rw-r--r--llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp b/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
index be0a612..cf8e337 100644
--- a/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
+++ b/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
@@ -314,6 +314,19 @@ static DecodeStatus decodeUImmOperand(MCInst &Inst, uint32_t Imm,
return MCDisassembler::Success;
}
+static DecodeStatus decodeUImmLog2XLenOperand(MCInst &Inst, uint32_t Imm,
+ int64_t Address,
+ const MCDisassembler *Decoder) {
+ assert(isUInt<6>(Imm) && "Invalid immediate");
+
+ if (!Decoder->getSubtargetInfo().hasFeature(RISCV::Feature64Bit) &&
+ !isUInt<5>(Imm))
+ return MCDisassembler::Fail;
+
+ Inst.addOperand(MCOperand::createImm(Imm));
+ return MCDisassembler::Success;
+}
+
template <unsigned N>
static DecodeStatus decodeUImmNonZeroOperand(MCInst &Inst, uint32_t Imm,
int64_t Address,
@@ -323,6 +336,14 @@ static DecodeStatus decodeUImmNonZeroOperand(MCInst &Inst, uint32_t Imm,
return decodeUImmOperand<N>(Inst, Imm, Address, Decoder);
}
+static DecodeStatus
+decodeUImmLog2XLenNonZeroOperand(MCInst &Inst, uint32_t Imm, int64_t Address,
+ const MCDisassembler *Decoder) {
+ if (Imm == 0)
+ return MCDisassembler::Fail;
+ return decodeUImmLog2XLenOperand(Inst, Imm, Address, Decoder);
+}
+
template <unsigned N>
static DecodeStatus decodeSImmOperand(MCInst &Inst, uint32_t Imm,
int64_t Address,