ComplexPattern

Hi,

I was wondering if someone could explain precisely what the ComplexPattern tablegen class does?

Here's the first line of the definition (from TargetSelectionDAG.td) for reference:

class ComplexPattern<ValueType ty, int numops, string fn,
                      list<SDNode> roots = [],
                      list<SDNodeProperty> props = [],
                      list<CPAttribute> attrs = []>

As far as I can tell it gives the name of a selection function (fn) that will be called to match that particular ComplexPattern. Should that function return true that pattern has matched. The match function can also fill in some operands that can be used later on (Number is specified by numops), ty presumably specifies the type of node that this match can be attempted on. Is my understanding of this correct?

The thing I'm still unsure about is roots, what exactly does this do? The comment above the definition specifies that 'RootNodes are the list of possible root nodes of the sub-dags to match' (RootsNodes is assigned to root so they're the same) but I can't make any sense of this.

Cheers,

Greg Chadwick

Hi,

I was wondering if someone could explain precisely what the
ComplexPattern tablegen class does?

ComplexPattern allows you to define arbitrary c++ code that does pattern matching. This is useful for things like the X86 addressing mode matcher, which have lots of special cases.

Here's the first line of the definition (from TargetSelectionDAG.td) for
reference:

class ComplexPattern<ValueType ty, int numops, string fn,
                     list<SDNode> roots = [],
                     list<SDNodeProperty> props = [],
                     list<CPAttribute> attrs = []>

As far as I can tell it gives the name of a selection function (fn) that
will be called to match that particular ComplexPattern. Should that
function return true that pattern has matched. The match function can
also fill in some operands that can be used later on (Number is
specified by numops), ty presumably specifies the type of node that this
match can be attempted on. Is my understanding of this correct?

Yes.

The thing I'm still unsure about is roots, what exactly does this do?
The comment above the definition specifies that 'RootNodes are the list
of possible root nodes of the sub-dags to match' (RootsNodes is assigned
to root so they're the same) but I can't make any sense of this.

I don't recall offhand, the best advice is to find an existing target that does it and look at what it is accomplishing.

-Chris