[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
Mon Oct 28 12:10:42 PDT 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());
+ Target &= Mask;
+ return true;
+ }
+ break;
+ }
+ case RISCV::ADDIW: {
+ if (auto TargetRegState = getGPRState(Inst.getOperand(1).getReg())) {
+ uint64_t Mask = ~((uint64_t)0) >> 32;
+ Target = *TargetRegState + SignExtend64<12>(Inst.getOperand(2).getImm());
+ Target &= Mask;
----------------
topperc wrote:
Why is this `&=` line needed?
https://github.com/llvm/llvm-project/pull/109914
More information about the llvm-commits
mailing list