diff options
author | Craig Topper <craig.topper@sifive.com> | 2023-02-06 21:23:21 -0800 |
---|---|---|
committer | Craig Topper <craig.topper@sifive.com> | 2023-02-06 21:23:21 -0800 |
commit | c7449c1770eef0345c32e2b6ad5344e9a06ed2c5 (patch) | |
tree | 3886cddc7c569d3b35b3d434f564ddb40e5b0a1d /llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp | |
parent | 6e67928642c25822c101316c5e03bb2a18b56715 (diff) | |
download | llvm-c7449c1770eef0345c32e2b6ad5344e9a06ed2c5.zip llvm-c7449c1770eef0345c32e2b6ad5344e9a06ed2c5.tar.gz llvm-c7449c1770eef0345c32e2b6ad5344e9a06ed2c5.tar.bz2 |
[RISCV] Refactor RISCVDisassembler::getInstruction to remove repeated code. NFC
For 4 byte instructions we were always setting size to 4 eventually. Same
for 2 byte instructions. So do it as soon as we know the from the opcode.
Add a return to the end of the 4 byte code so we don't have to have an else
around the 2 byte code.
Differential Revision: https://reviews.llvm.org/D143445
Diffstat (limited to 'llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp')
-rw-r--r-- | llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp | 62 |
1 files changed, 26 insertions, 36 deletions
diff --git a/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp b/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp index ae1a900..17a8d48 100644 --- a/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp +++ b/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp @@ -444,74 +444,64 @@ DecodeStatus RISCVDisassembler::getInstruction(MCInst &MI, uint64_t &Size, Size = 0; return MCDisassembler::Fail; } + Size = 4; + Insn = support::endian::read32le(Bytes.data()); + if (STI.getFeatureBits()[RISCV::FeatureStdExtZdinx] && !STI.getFeatureBits()[RISCV::Feature64Bit]) { LLVM_DEBUG(dbgs() << "Trying RV32Zdinx table (Double in Integer and" "rv32)\n"); Result = decodeInstruction(DecoderTableRV32Zdinx32, MI, Insn, Address, this, STI); - if (Result != MCDisassembler::Fail) { - Size = 4; + if (Result != MCDisassembler::Fail) return Result; - } } - if (STI.getFeatureBits()[RISCV::FeatureStdExtZfinx]) { LLVM_DEBUG(dbgs() << "Trying RVZfinx table (Float in Integer):\n"); Result = decodeInstruction(DecoderTableRVZfinx32, MI, Insn, Address, this, STI); - if (Result != MCDisassembler::Fail) { - Size = 4; + if (Result != MCDisassembler::Fail) return Result; - } } if (STI.getFeatureBits()[RISCV::FeatureVendorXVentanaCondOps]) { LLVM_DEBUG(dbgs() << "Trying Ventana custom opcode table:\n"); Result = decodeInstruction(DecoderTableVentana32, MI, Insn, Address, this, STI); - if (Result != MCDisassembler::Fail) { - Size = 4; + if (Result != MCDisassembler::Fail) return Result; - } } if (STI.getFeatureBits()[RISCV::FeatureVendorXTHeadVdot]) { LLVM_DEBUG(dbgs() << "Trying XTHeadVdot custom opcode table:\n"); Result = decodeInstruction(DecoderTableTHeadV32, MI, Insn, Address, this, STI); - if (Result != MCDisassembler::Fail) { - Size = 4; + if (Result != MCDisassembler::Fail) return Result; - } } LLVM_DEBUG(dbgs() << "Trying RISCV32 table :\n"); - Result = decodeInstruction(DecoderTable32, MI, Insn, Address, this, STI); - Size = 4; - } else { - if (Bytes.size() < 2) { - Size = 0; - return MCDisassembler::Fail; - } - Insn = support::endian::read16le(Bytes.data()); + return decodeInstruction(DecoderTable32, MI, Insn, Address, this, STI); + } - if (!STI.getFeatureBits()[RISCV::Feature64Bit]) { - LLVM_DEBUG( - dbgs() << "Trying RISCV32Only_16 table (16-bit Instruction):\n"); - // Calling the auto-generated decoder function. - Result = decodeInstruction(DecoderTableRISCV32Only_16, MI, Insn, Address, - this, STI); - if (Result != MCDisassembler::Fail) { - Size = 2; - return Result; - } - } + if (Bytes.size() < 2) { + Size = 0; + return MCDisassembler::Fail; + } + Size = 2; + + Insn = support::endian::read16le(Bytes.data()); - LLVM_DEBUG(dbgs() << "Trying RISCV_C table (16-bit Instruction):\n"); + if (!STI.getFeatureBits()[RISCV::Feature64Bit]) { + LLVM_DEBUG( + dbgs() << "Trying RISCV32Only_16 table (16-bit Instruction):\n"); // Calling the auto-generated decoder function. - Result = decodeInstruction(DecoderTable16, MI, Insn, Address, this, STI); - Size = 2; + Result = decodeInstruction(DecoderTableRISCV32Only_16, MI, Insn, Address, + this, STI); + if (Result != MCDisassembler::Fail) + return Result; } - return Result; + LLVM_DEBUG(dbgs() << "Trying RISCV_C table (16-bit Instruction):\n"); + // Calling the auto-generated decoder function. + return decodeInstruction(DecoderTable16, MI, Insn, Address, this, STI); } |