Page MenuHomePhabricator

[RISCV][MC] Print absolute targets of branch instructions
Needs ReviewPublic

Authored by simoncook on Thu, May 21, 1:04 AM.

Details

Summary

This changes the output of branch/jump instructions to show the absolute
addresses of targets of branch and jump instructions (in hexadecimal,
better matching GNU objdump output)

llvm-objdump -d output (before)
       0: 6f 00 00 00                   j       0
       4: 63 12 00 00                   bnez    zero, 4
       8: 6f f0 df ff                   j       -4

llvm-objdump -d output (after)
       0: 6f 00 00 00                   j       0x0
       4: 63 12 00 00                   bnez    zero, 0x8
       8: 6f f0 df ff                   j       0x4

In RISC-V these operands are not noted as OPERAND_PCREL, and the backend
uses this field to store other information, I have extended TableGen to
handle this case.

All RISC-V MC tests have been updated to check for the correct output
as presented by both llvm-mc and llvm-objdump.

Diff Detail

Event Timeline

simoncook created this revision.Thu, May 21, 1:04 AM

Why does RISC-V need PrintRequiresAddr?

Why does RISC-V need PrintRequiresAddr?

The rationale behind this was that to do PC relative addressing the operand print method needs the current address, and that is only in LLVM today if the operand type is OPERAND_PCREL. The RISC-V backend uses custom values for these and is used in verifyInstruction in RISCVInstrInfo to verify immediates fit into fields. I added PrintRequiresAddr as a second way of getting that behaviour for backends which use OperandType/OperandNamespace for custom things, rather than only if the type is MCOI::OPERAND_PCREL.