diff options
| author | Fangrui Song <maskray@google.com> | 2020-03-22 23:03:09 -0700 |
|---|---|---|
| committer | Fangrui Song <maskray@google.com> | 2020-03-26 08:32:29 -0700 |
| commit | 3eef47407b7247513f125833abc688cea3a1d218 (patch) | |
| tree | b2ade11d782ef6aaf5112ad2c073016db82d80ab /llvm/lib | |
| parent | 3ff3c6986b1aea1ca0630bf844f8567780eaec90 (diff) | |
| download | llvm-3eef47407b7247513f125833abc688cea3a1d218.zip llvm-3eef47407b7247513f125833abc688cea3a1d218.tar.gz llvm-3eef47407b7247513f125833abc688cea3a1d218.tar.bz2 | |
[PPCInstPrinter] Change printBranchOperand(calltarget) to print the target address in hexadecimal form
```
// llvm-objdump -d output (before)
0: bl .-4
4: bl .+0
8: bl .+4
// llvm-objdump -d output (after) ; GNU objdump -d
0: bl 0xfffffffc / bl 0xfffffffffffffffc
4: bl 0x4
8: bl 0xc
```
Many Operand's are not annotated as OPERAND_PCREL.
They are not affected (e.g. `b .+67108860`). I plan to fix them in future patches.
Modified test/tools/llvm-objdump/ELF/PowerPC/branch-offset.s to test
address space wraparound for powerpc32 and powerpc64.
Reviewed By: sfertile, jhenderson
Differential Revision: https://reviews.llvm.org/D76591
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/Target/PowerPC/MCTargetDesc/PPCInstPrinter.cpp | 35 | ||||
| -rw-r--r-- | llvm/lib/Target/PowerPC/MCTargetDesc/PPCInstPrinter.h | 8 |
2 files changed, 25 insertions, 18 deletions
diff --git a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCInstPrinter.cpp b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCInstPrinter.cpp index 4dc2b35..c3685e8 100644 --- a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCInstPrinter.cpp +++ b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCInstPrinter.cpp @@ -413,23 +413,30 @@ void PPCInstPrinter::printU16ImmOperand(const MCInst *MI, unsigned OpNo, printOperand(MI, OpNo, O); } -void PPCInstPrinter::printBranchOperand(const MCInst *MI, unsigned OpNo, - raw_ostream &O) { +void PPCInstPrinter::printBranchOperand(const MCInst *MI, uint64_t Address, + unsigned OpNo, raw_ostream &O, + bool RelativeForm) { if (!MI->getOperand(OpNo).isImm()) return printOperand(MI, OpNo, O); - - // Branches can take an immediate operand. This is used by the branch - // selection pass to print, for example `.+8` (for ELF) or `$+8` (for AIX) to - // express an eight byte displacement from the program counter. - if (!TT.isOSAIX()) - O << "."; - else - O << "$"; - int32_t Imm = SignExtend32<32>((unsigned)MI->getOperand(OpNo).getImm() << 2); - if (Imm >= 0) - O << "+"; - O << Imm; + if (PrintBranchImmAsAddress && !RelativeForm) { + uint64_t Target = Address + Imm; + if (!TT.isPPC64()) + Target &= 0xffffffff; + O << formatHex(Target); + } else { + // Branches can take an immediate operand. This is used by the branch + // selection pass to print, for example `.+8` (for ELF) or `$+8` (for AIX) + // to express an eight byte displacement from the program counter. + if (!TT.isOSAIX()) + O << "."; + else + O << "$"; + + if (Imm >= 0) + O << "+"; + O << Imm; + } } void PPCInstPrinter::printAbsBranchOperand(const MCInst *MI, unsigned OpNo, diff --git a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCInstPrinter.h b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCInstPrinter.h index 93ac2ce..6339a42 100644 --- a/llvm/lib/Target/PowerPC/MCTargetDesc/PPCInstPrinter.h +++ b/llvm/lib/Target/PowerPC/MCTargetDesc/PPCInstPrinter.h @@ -64,10 +64,10 @@ public: void printS34ImmOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O); void printU16ImmOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O); void printImmZeroOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O); - void printBranchOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O); - void printBranchOperand(const MCInst *MI, uint64_t /*Address*/, unsigned OpNo, - raw_ostream &O) { - printBranchOperand(MI, OpNo, O); + void printBranchOperand(const MCInst *MI, uint64_t Address, unsigned OpNo, + raw_ostream &O, bool RelativeForm = false); + void printBranchOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O) { + printBranchOperand(MI, 0, OpNo, O, true); } void printAbsBranchOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O); void printTLSCall(const MCInst *MI, unsigned OpNo, raw_ostream &O); |
