This is an archive of the discontinued LLVM Phabricator instance.

[TableGen] FixedLenDecoderEmitter: allow for dummy operand in MCInst
AbandonedPublic

Authored by tpr on Jul 6 2018, 8:18 AM.

Details

Summary

Normally a "dummy" operand, one named in InOperandList or OutOperandList
but with no bits in the instruction encoding, is not included in an
MCInst, and the autogenerated decoding code for the disassembler
generated by FixedLenDecodeEmitter reflects that: for any such dummy
operand, no MCOperand is pushed onto the MCInst.

I have a case where it would help commoning up of essentially the same
instruction between different variants of the cpu to have a dummy
operand represented in the MCInst.

Thus I have added a new field in an instruction "hasDummyOperands".
Normally 0, when set to 1 it causes the disassembler to push an
immediate zero MCOperand for any dummy operand.

There is no test for this, but a future AMDGPU commit will use it and
thus exercise it in its tests.

Change-Id: I82b7e1f75b466f24889434c1733c6dd78ec91dbd

Diff Detail

Event Timeline

tpr created this revision.Jul 6 2018, 8:18 AM
tpr added a comment.Jul 6 2018, 8:28 AM

The AMDGPU change that uses this is D49029.

arsenm added inline comments.Jul 6 2018, 9:25 AM
include/llvm/Target/Target.td
585–589

Dummy operand seems like the wrong name for this. Also can't this property be inferred already by checking which operands appear in the encodings? Why does an explicit bit need to be added for it?

tpr added inline comments.Jul 8 2018, 3:05 PM
include/llvm/Target/Target.td
585–589

If there is an operand that does not appear in the instruction encoding, does the MCInst decoder leave a gap for it by adding a dummy operand, or not? The latter is the current behavior, and there is some code relying on that. The new hasDummyOperands tells it to do the first behavior.

Suggestions welcome for better name.

arsenm added inline comments.Jul 9 2018, 1:12 AM
include/llvm/Target/Target.td
585–589

IncludeUnencodedOperands or something like that?

tpr updated this revision to Diff 155894.Jul 17 2018, 8:37 AM

V2: Renamed to UseUnencodedOperands.

tpr added a comment.Jul 17 2018, 8:38 AM

Actually I renamed it to IncludeUnencodedOperands.

Why do you need this? Do you have MCInsts with operands that are not encoded?

tpr added a comment.Jul 18 2018, 12:31 AM

Yes we do in AMDGPU. See D49029 for a simple example of where we can use this mechanism to replace a hack where the disassembler has to manually insert an operand. I think there are some in ARM as well.

As far as I can tell, there are four kinds of operands when it comes to fixed-length encoding / decoding:

  1. Normal operands that are used and encoded and decoded normally using the automatic machinery.
  2. Tied operands.
  3. Operands that are used, but for some reason need a special mechanism for encoding and decoding.
  4. Operands that aren't used and aren't encoded / decoded.

As far as I can tell, this new mechanism would only make sense for the last category of operands. The obvious question is: why do we have such operands in the first place?

From the other patch, an example of this is the src2_modifier on multiply-accumulate V_MAC & friends instructions in AMDGPU. But since this operand isn't actually ever used, why don't we remove it instead?

Would it be possible to remove src2_modifiers from V_MAC_* instead? It seems odd to me to have operands in a MachineInstruction that are not actually ever used and must be 0.

tpr abandoned this revision.Aug 17 2018, 8:06 AM