This is an archive of the discontinued LLVM Phabricator instance.

[GlobalISel] improved interface to MachineIRBuilder::buildInstr
ClosedPublic

Authored by t.p.northover on Jul 26 2016, 10:18 AM.

Details

Summary

Hi,

I've been thinking about how to make MachineInstrBuilder scale as pleasantly as possible, and come up with this idea. Basically, instead of

MIRBuilder.buildInstr(Opcode, Ty, Res, Op0, Op1);

you'd have to write

MIRBuilder.buildInstr(Opcode, Ty, MIB::Def(Res), MIB::Use(Op0), MIB::Use(Op1));

(and similar). This has a few advantages:

  • Removes the implicit specialness of the first register (inherited from BuildMI, where it's caught out at least two people I know of, including me).
  • Allows other kinds of operands that we'll want to be handled uniformly (FrameIndex, MBB, Imm, ...).

On the other hand, there are disadvantages:

  • The usual opaque template error messages when you get it wrong.
  • More verbose in the common case of single-def, multiple-uses, register only (instructions like this will be less common for target opcodes than generic ones though).
  • Feels like a minor riff on the old MachineInstrBuilder interface. Perhaps what we'd have used then if we had variadic templates, or perhaps there's a good reason we didn't?

Anyone got any feelings? On the whole I think it has potential.

Diff Detail

Repository
rL LLVM

Event Timeline

t.p.northover retitled this revision from to RFC[GlobalISel]: improved interface or unholy monstrosity?.
t.p.northover updated this object.
t.p.northover added reviewers: ab, qcolombet, arsenm.
t.p.northover set the repository for this revision to rL LLVM.
t.p.northover added a subscriber: llvm-commits.
qcolombet accepted this revision.Jul 26 2016, 10:34 AM
qcolombet edited edge metadata.

Hi Tim,

I like the idea!
That's a +1 for me!

Cheers,
Q.

This revision is now accepted and ready to land.Jul 26 2016, 10:34 AM
arsenm edited edge metadata.Jul 26 2016, 10:35 AM

This seems less awkward for instructions with multiple results, adding a separate addReg(x, RegState::Define) always feels dirty

t.p.northover retitled this revision from RFC[GlobalISel]: improved interface or unholy monstrosity? to [GlobalISel] improved interface to MachineIRBuilder::buildInstr.
t.p.northover edited edge metadata.

OK, given the initial responses I've polished the patch up a bit and I'm converting it into a real review. I've not added all the weird corner-cases yet since we've got no real way to use them. Extending the interface as GlobalISel gains the features needed to test them ought to be a simple copy/paste/edit job.

OK to commit as is, or does anyone have some suggestions for improvements?

ab edited edge metadata.Jul 27 2016, 8:02 AM

It does seem nicer!

Here's a simpler alternative: have buildInstr return the builder, and replace addReg with explicit addDef/addUse? That spares you the template hackery for a similar result. WDYT?

Excellent idea! I can't really see any aspect it doesn't improve on this patch. I'll get to work.

t.p.northover edited edge metadata.

Simplify the change and interface based on Ahmed's idea.

In D22820#497728, @ab wrote:

It does seem nicer!

Here's a simpler alternative: have buildInstr return the builder, and replace addReg with explicit addDef/addUse? That spares you the template hackery for a similar result. WDYT?

I also like this idea, because it makes it really easy to add immediate operands.

qcolombet closed this revision.Nov 10 2016, 3:46 PM

This landed in r277176 as far as I can tell.