[llvm] [LoongArch][Disassembler] Add symbolic operands for decoded immediates (PR #217971)

Rong Mantle Bao via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 24 03:09:24 PDT 2026


================
@@ -142,18 +142,28 @@ static DecodeStatus decodeUImmOperand(MCInst &Inst, uint64_t Imm,
                                       int64_t Address,
                                       const MCDisassembler *Decoder) {
   assert(isUInt<N>(Imm) && "Invalid immediate");
-  Inst.addOperand(MCOperand::createImm(Imm + P));
+  const int64_t DecodedImm = Imm + P;
+  if (!Decoder->tryAddingSymbolicOperand(Inst, DecodedImm, Address,
+                                         /*IsBranch=*/false, 0, 0, 4))
+    Inst.addOperand(MCOperand::createImm(DecodedImm));
   return MCDisassembler::Success;
 }
 
-template <unsigned N, unsigned S = 0>
+template <unsigned N, unsigned S = 0, bool IsPCRelBranch = false>
 static DecodeStatus decodeSImmOperand(MCInst &Inst, uint64_t Imm,
                                       int64_t Address,
                                       const MCDisassembler *Decoder) {
   assert(isUInt<N>(Imm) && "Invalid immediate");
   // Shift left Imm <S> bits, then sign-extend the number in the bottom <N+S>
   // bits.
-  Inst.addOperand(MCOperand::createImm(SignExtend64<N + S>(Imm << S)));
+  const int64_t DecodedImm = SignExtend64<N + S>(Imm << S);
+  const int64_t Value =
+      IsPCRelBranch ? static_cast<int64_t>(static_cast<uint64_t>(Address) +
+                                           static_cast<uint64_t>(DecodedImm))
+                    : DecodedImm;
+  if (!Decoder->tryAddingSymbolicOperand(Inst, Value, Address, IsPCRelBranch, 0,
+                                         0, 4))
----------------
CSharperMantle wrote:

Ditto.

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


More information about the llvm-commits mailing list