This is an archive of the discontinued LLVM Phabricator instance.

[TableGen] Fix printing second PC-relative operand
ClosedPublic

Authored by ikudrin on Jun 22 2021, 4:08 AM.

Details

Summary

If an instruction has several operands and a PC-relative one is not the first of them, the generator may produce the code that does not pass the Address parameter to the printout method. For example, for an Arm instruction LE LR, $imm, it reuses the same code as for other instructions where the second operand is not PC-relative:

void ARMInstPrinter::printInstruction(...) {
...
  case 11:
    // BF16VDOTI_VDOTD, BF16VDOTI_VDOTQ, BF16VDOTS_VDOTD, ...
    printOperand(MI, 1, STI, O);
    O << ", ";
    printOperand(MI, 2, STI, O);
    break;
...

The patch fixes that by considering PCRel when comparing AsmWriterOperand values.

Diff Detail

Event Timeline

ikudrin created this revision.Jun 22 2021, 4:08 AM
ikudrin requested review of this revision.Jun 22 2021, 4:08 AM
MaskRay accepted this revision.Jun 22 2021, 8:27 PM

I know little about llvm/utils/TableGen/AsmWriterEmitter.cpp, but after debugging it a bit, I think this is reasonable.

llvm/test/TableGen/AsmWriterPCRelOp.td
33

// CHECK-LABEL: ArchInstPrinter::printInstruction(

This revision is now accepted and ready to land.Jun 22 2021, 8:27 PM
MaskRay added inline comments.Jun 22 2021, 8:28 PM
llvm/test/TableGen/AsmWriterPCRelOp.td
2

%t.log => | FileCheck %s

ikudrin added inline comments.Jun 22 2021, 10:29 PM
llvm/test/TableGen/AsmWriterPCRelOp.td
2

Thanks a lot! I'll fix that on commit.

33

I am afraid I am not following you. What is the difference and how CHECK-LABEL can be useful in this case?

MaskRay added inline comments.Jun 22 2021, 10:41 PM
llvm/test/TableGen/AsmWriterPCRelOp.td
33

When there are multiple functions, -LABEL patterns are matched first and they break the input into multiple regions. The FileCheck failing diagnostic can be slightly better with -LABEL. For this case I guess -LABEL may be an overkill. Do your original pattern is fine.

ikudrin added inline comments.Jun 22 2021, 10:51 PM
llvm/test/TableGen/AsmWriterPCRelOp.td
33

Thanks for explaining. I'll stick with my original check then.

This revision was landed with ongoing or failed builds.Jun 22 2021, 11:28 PM
This revision was automatically updated to reflect the committed changes.