[PATCH] D30089: [globalisel][tblgen] Add support for ComplexPatterns

Daniel Sanders via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 10 15:43:19 PST 2017


dsanders added a comment.

In https://reviews.llvm.org/D30089#698324, @qcolombet wrote:

> > The constructor call comes from the need to call addOperand(). If we reset the operand list for the placeholder instruction on each call to selectImpl() then we would need something like:
> > 
> > PlaceholderInsn.addOperand(MachineOperand::CreatePlaceholder());
> >  PlaceholderInsn.addOperand(MachineOperand::CreatePlaceholder());
> >  if (matches && selectComplexPattern(PlaceholderInsn.getOperand(0), PlaceholderInsn.getOperand(1))) {
> > 
> >   BuildMI(...).add(PlaceholderInsn.getOperand(0)).add(PlaceholderInsn.getOperand(1));
> >   ...
> > 
> > }
> >  PlaceholderInsn.resetOperands();
> >  Each call to addOperand() involves a placement new operator which uses the copy-constructor and therefore pays the same overhead as the current local variable approach.
>
> I was actually expecting more something like:
>  PlaceHolderInst.setNumOperand(NbOp);
>  With that call just allocating/resizing the operand array accordingly. The operands created could be left uninitialized as they are supposed to be all properly set by the matching.


Ah ok, I see how that would avoid the redundant initializations. Wouldn't it be more efficient to call setNumOperands(MaxNumOperands) in advance though to save on re-allocating and copying the array?

>> I think your main concern is that the overhead is unnecessarily paid on each call to selectImpl(). I've updated the patch with a version that only pays the constructor overhead once (during <Target>InstructionSelection's constructor). Does that resolve your concerns?
> 
> Yes, partly. I believe we don't need the OperandHolder all together, but this is an optimization that we definitely don't need to do now.

I'm not sure we can eliminate the placeholders since storing directly to the output instruction requires us to build that instruction before we've finished matching but I'll have a think on how we can do it.

> All in all, the patch looks sensible to me.

Thanks.


https://reviews.llvm.org/D30089





More information about the llvm-commits mailing list