Skip to content

[SystemZ] Support PrintBranchImmAsAddress in disassembler #141064

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions llvm/lib/Target/SystemZ/Disassembler/SystemZDisassembler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,9 @@ static DecodeStatus decodePCDBLOperand(MCInst &Inst, uint64_t Imm,
uint64_t Address, bool isBranch,
const MCDisassembler *Decoder) {
assert(isUInt<N>(Imm) && "Invalid PC-relative offset");
uint64_t Value = SignExtend64<N>(Imm) * 2 + Address;
uint64_t Value = SignExtend64<N>(Imm) * 2;

if (!tryAddingSymbolicOperand(Value, isBranch, Address, 2, N / 8,
if (!tryAddingSymbolicOperand(Value + Address, isBranch, Address, 2, N / 8,
Inst, Decoder))
Inst.addOperand(MCOperand::createImm(Value));

Expand Down
28 changes: 22 additions & 6 deletions llvm/lib/Target/SystemZ/MCTargetDesc/SystemZInstPrinterCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,22 +148,38 @@ void SystemZInstPrinterCommon::printU48ImmOperand(const MCInst *MI, int OpNum,
printUImmOperand<48>(MI, OpNum, O);
}

void SystemZInstPrinterCommon::printPCRelOperand(const MCInst *MI, int OpNum,
void SystemZInstPrinterCommon::printPCRelOperand(const MCInst *MI,
uint64_t Address, int OpNum,
raw_ostream &O) {
const MCOperand &MO = MI->getOperand(OpNum);

// If the label has already been resolved to an immediate offset (say, when
// we're running the disassembler), just print the immediate.
if (MO.isImm()) {
WithMarkup M = markup(O, Markup::Immediate);
O << "0x";
O.write_hex(MO.getImm());
} else
int64_t Offset = MO.getImm();
if (PrintBranchImmAsAddress)
markup(O, Markup::Target) << formatHex(Address + Offset);
else
markup(O, Markup::Immediate) << formatImm(Offset);
return;
}

// If the branch target is simply an address then print it in hex.
const MCConstantExpr *BranchTarget = dyn_cast<MCConstantExpr>(MO.getExpr());
int64_t TargetAddress;
if (BranchTarget && BranchTarget->evaluateAsAbsolute(TargetAddress)) {
markup(O, Markup::Target) << formatHex((uint64_t)TargetAddress);
} else {
// Otherwise, just print the expression.
MO.getExpr()->print(O, &MAI);
}
}

void SystemZInstPrinterCommon::printPCRelTLSOperand(const MCInst *MI,
uint64_t Address, int OpNum,
raw_ostream &O) {
// Output the PC-relative operand.
printPCRelOperand(MI, OpNum, O);
printPCRelOperand(MI, Address, OpNum, O);

// Output the TLS marker if present.
if ((unsigned)OpNum + 1 < MI->getNumOperands()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,8 @@ class SystemZInstPrinterCommon : public MCInstPrinter {
void printS32ImmOperand(const MCInst *MI, int OpNum, raw_ostream &O);
void printU32ImmOperand(const MCInst *MI, int OpNum, raw_ostream &O);
void printU48ImmOperand(const MCInst *MI, int OpNum, raw_ostream &O);
void printPCRelOperand(const MCInst *MI, int OpNum, raw_ostream &O);
void printPCRelOperand(const MCInst *MI, uint64_t /*Address*/, int OpNum,
raw_ostream &O) {
printPCRelOperand(MI, OpNum, O);
}
void printPCRelOperand(const MCInst *MI, uint64_t Address, int OpNum,
raw_ostream &O);
void printPCRelTLSOperand(const MCInst *MI, uint64_t Address, int OpNum,
raw_ostream &O);

Expand Down
Loading