[llvm] [feature][riscv] handle target address calculation in llvm-objdump disassembly for riscv (PR #109914)

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 19 12:27:24 PST 2024


================
@@ -230,6 +246,97 @@ class RISCVMCInstrAnalysis : public MCInstrAnalysis {
     return false;
   }
 
+  bool evaluateInstruction(const MCInst &Inst, uint64_t Addr, uint64_t Size,
+                           uint64_t &Target) const override {
+    switch(Inst.getOpcode()) {
+      default:
+        return false;
+      case RISCV::ADDI: {
+        if (auto TargetRegState = getGPRState(Inst.getOperand(1).getReg())) {
+          // TODO: Figure out ways to find the actual value of XLEN during analysis
+          int XLEN = 32;
+          uint64_t Mask = ~((uint64_t)0) >> (64 - XLEN);
+          Target = *TargetRegState + SignExtend64<12>(Inst.getOperand(2).getImm());
----------------
topperc wrote:

That's correct. LUI and AUIPC immediates are 20-bit unsigned values. The 12-bit immediates for ADDI, XORI, ANDI, ORI, loads, stores are always in sign extended form.

https://github.com/llvm/llvm-project/pull/109914


More information about the llvm-commits mailing list