This is an archive of the discontinued LLVM Phabricator instance.

[globalisel][tablegen] Add experimental support for OperandWithDefaultOps, PredicateOperand, and OptionalDefOperand
ClosedPublic

Authored by dsanders on Mar 20 2017, 9:35 AM.

Details

Summary

As far as instruction selection is concerned, all three appear to be same thing.

Support for these operands is experimental since AArch64 doesn't make use
of them and the in-tree targets that do use them (AMDGPU for
OperandWithDefaultOps, AMDGPU/ARM/Hexagon/Lanai for PredicateOperand, and ARM
for OperandWithDefaultOps) are not using tablegen-erated GlobalISel yet.

Event Timeline

dsanders created this revision.Mar 20 2017, 9:35 AM
dsanders updated this revision to Diff 92343.Mar 20 2017, 9:39 AM

Add a default register test

dsanders updated this revision to Diff 92911.Mar 24 2017, 3:11 AM

Add the test case without accidentally removing the rest of the patch.

ab edited edge metadata.Mar 31 2017, 11:35 AM

This seems to only add optional uses, what about OptionalDefOperand? (I'm fine with "we don't need that", but I don't see anything that would make the import fail)

rovka added inline comments.Apr 3 2017, 9:28 AM
test/TableGen/GlobalISelEmitter.td
29

Could you also add a test with 2 ops for the same operand? That would correspond to ARM's predicate operand.

242

Sorry I didn't notice this before, but I'm not sure this is a good use for CHECK-LABEL. IIUC the labels are supposed to be unique within the file. I might be wrong about it, but I thought I should bring it up just in case... Maybe we could generate some comment next to each lambda to disambiguate between them?

utils/TableGen/GlobalISelEmitter.cpp
36 ↗(On Diff #92911)

Nit: This is not properly ordered (should go above Statistic.h)

1436 ↗(On Diff #92911)

I'm a bit nervous about what happens if we *do* have a value for one of the default operands. Won't that mess up the whole algorithm? AFAICT we're not bailing out if we end up with too many operands...

1437 ↗(On Diff #92911)

Nit: ARM has lots of instructions with 2 default operands (the pred and the condition code). I think it wouldn't hurt much to use 2 here to avoid going to the heap in those cases.

In D31135#715631, @ab wrote:

This seems to only add optional uses, what about OptionalDefOperand? (I'm fine with "we don't need that", but I don't see anything that would make the import fail)

I think this patch implements OptionalDefOperand but the ISel aspects of OptionalDefOperand are a bit strange. There's three uses of it in LLVM at the moment, all of them in ARM:

  • ldstm_mode is never used as far as I can tell and the default operand is '1' which doesn't make sense for an explicit def
  • Despite its name, cc_out only ever appears at the end of the input operand list (see the sI class) and seems to behave like OperandWithDefaultOps
  • s_cc_out is used as an optional def but only appears in InstAlias's
test/TableGen/GlobalISelEmitter.td
29

Ok

242

There's no requirement that they're unique, it's just that CHECK-LABEL can match in unexpected places if they're not distinct enough. In this case, it's being used to chop up the input into individual rules so that CHECK doesn't match in another rules code although this is moot now that we only have CHECK-NEXT's.

Maybe we could generate some comment next to each lambda to disambiguate between them?

Now that you mention it, the pattern comment (e.g. line 253) should probably be in front of the 'if ([&]() {' line. I think that's for a different patch though.

utils/TableGen/GlobalISelEmitter.cpp
36 ↗(On Diff #92911)

Yep

1436 ↗(On Diff #92911)

Are you thinking of the case where the OperandWithDefaultOps has 2 operands and a Pat<> provides just one? Yes, that would mess up the algorithm. I don't think anyone has used OperandWithDefaultOps like that but I should at least check for it so we fail nicely if someone has done that.

1437 ↗(On Diff #92911)

Ok

dsanders updated this revision to Diff 94346.Apr 6 2017, 3:59 AM
dsanders marked 6 inline comments as done.

Add 2-default-operand test case
Check for too many operands
Nits

rovka accepted this revision.Apr 11 2017, 3:57 AM

LGTM, thanks.

This revision is now accepted and ready to land.Apr 11 2017, 3:57 AM
dsanders closed this revision.Apr 12 2017, 1:35 AM
This revision was automatically updated to reflect the committed changes.