This is an archive of the discontinued LLVM Phabricator instance.

[TableGen][X86] Add Size field to X86MemOperand class
ClosedPublic

Authored by Amir on Jun 14 2022, 1:56 PM.

Details

Summary

Set Size appropriately in operand definitions and query it for dumping memory
operand size table getMemOperandSize (follow-up use D126116) and
X86Disassembler::getMemOperandSize.

Excerpt from a produced getMemOperandSize table for X86:

static int getMemOperandSize(int OpType) {
  switch (OpType) {
  default: return 0;
  case OpTypes::i8mem:
  case OpTypes::i8mem_NOREX:
    return 8;

  case OpTypes::f16mem:
  case OpTypes::i16mem:
    return 16;

  case OpTypes::f32mem:
  case OpTypes::i32mem:
    return 32;
...

Diff Detail

Event Timeline

Amir created this revision.Jun 14 2022, 1:56 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 14 2022, 1:56 PM
Herald added subscribers: jsji, pengfei. · View Herald Transcript
Amir requested review of this revision.Jun 14 2022, 1:56 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 14 2022, 1:56 PM
skan added inline comments.Jun 14 2022, 7:58 PM
llvm/utils/TableGen/InstrInfoEmitter.cpp
467

Could we add one field for class X86MemAsmOperand explicitly? I don't think regex is good way here...

Amir updated this revision to Diff 437040.Jun 14 2022, 10:53 PM

Extend X86MemOperand with Size field.
Only process X86MemOperands in GET_INSTRINFO_MEM_OPERAND_SIZE.
Make i8mem_NOREX inherit from X86MemOperand.

Amir marked an inline comment as done.Jun 14 2022, 10:56 PM
Amir added inline comments.
llvm/utils/TableGen/InstrInfoEmitter.cpp
467

I've extended X86MemOperand class (I think that's the one you had in mind) with Size field.
It's being queried explicitly.

The alternative is to check something like

if (Op->getValueAsString("OperandType") != "OPERAND_MEMORY" ||
    Op->isValueUnset("Size"))
  continue;

to be able to cover operands other than X86MemOperand/targets other than X86.

pengfei accepted this revision.Jun 14 2022, 11:29 PM

LGTM. The summary need to update too.

llvm/utils/TableGen/InstrInfoEmitter.cpp
25

This is not needed, right?

This revision is now accepted and ready to land.Jun 14 2022, 11:29 PM

What is this going to be used for?

skan added inline comments.Jun 15 2022, 8:31 AM
llvm/lib/Target/X86/X86InstrInfo.td
397

Could you also simply the function getMemOperandSize in X86RecognizableInstr.cpp in this patch? You can return value of Size now.

skan added a comment.Jun 15 2022, 8:32 AM

What is this going to be used for?

I think it is for D126116.

Amir edited the summary of this revision. (Show Details)Jun 15 2022, 10:37 AM
Amir updated this revision to Diff 437242.Jun 15 2022, 10:39 AM
Amir marked an inline comment as done.

Remove Regex include

Amir updated this revision to Diff 437245.Jun 15 2022, 10:49 AM

Use X86MemOperand->Size in X86Disassembler::getMemOperandSize.

Amir marked 2 inline comments as done.Jun 15 2022, 10:53 AM
Amir added inline comments.
llvm/lib/Target/X86/X86InstrInfo.td
397

Done. I'm not 100% sure it's an equivalent replacement – i.e. if all Operand's that have ParserMatchClass->Name = Mem* are actually X86MemOperand's. But the check-llvm test passed locally.

Amir edited the summary of this revision. (Show Details)Jun 15 2022, 10:57 AM
Amir retitled this revision from [TableGen][X86] Emit memory operand size table to [TableGen][X86] Add Size field to X86MemOperand class .
Amir edited the summary of this revision. (Show Details)
Amir marked an inline comment as done.Jun 15 2022, 10:59 AM
Amir updated this revision to Diff 437255.Jun 15 2022, 11:03 AM
Amir retitled this revision from [TableGen][X86] Add Size field to X86MemOperand class to [TableGen][X86] Add Size field to X86MemOperand class.

Rebase

skan accepted this revision.Jun 15 2022, 6:58 PM

LGTM

This revision was landed with ongoing or failed builds.Jun 19 2022, 11:47 AM
This revision was automatically updated to reflect the committed changes.