This is an archive of the discontinued LLVM Phabricator instance.

[RISCV][MC] Print absolute targets of branch instructions
AcceptedPublic

Authored by simoncook on May 21 2020, 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.May 21 2020, 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.

MaskRay accepted this revision.Sep 20 2020, 10:33 AM

This may require rebasing but the idea looks great to me.

llvm/include/llvm/Target/Target.td
811

Consider moving it beside another bit field.

llvm/utils/TableGen/CodeGenInstruction.h
89

"Don’t duplicate function or class name at the beginning of the comment."

https://llvm.org/docs/CodingStandards.html#doxygen-use-in-documentation-comments

This revision is now accepted and ready to land.Sep 20 2020, 10:33 AM

Thanks for reviewing. I'll rebase and add this shortly.

llvm/utils/TableGen/CodeGenInstruction.h
89

Noted. I added this since every other member in this class (except for) Constraints did this, and followed for consistency.