Pat<> & tlbgen

Can someone explain the magic behind the Pat<> construct and tblgen.

From X86InstrSSE.td:

def : Pat<(v4f32 (vector_shuffle VR128:$src, (undef), MOVDDUP_shuffle_mask)),
          (MOVLHPSrr VR128:$src, VR128:$src)>, Requires<[HasSSE1]>;

Where's the code in tblgen to emit the matching code for this? I'm trying to
extend it so that Pat<> can be used as a general subclass for AVX:

class Base<dag pat, dag result, ...> : Pat<dag, result> ...;

multiclass foo<dag pat, dag result, ...> {
  def A : Base<pat, result, ...>;
  def B : Base<pat, result, ...>;
}

The idea is to let the user write ALL of the patterns for a mnemonic in one
place:

defm MOVLH : foo<(v4f32 (vector_shuffle VR128:$src, (undef),
                         MOVDDUP_shuffle_mask)),
                 (MOVLHPSrr VR128:$src, VR128:$src),
                 some.other.params.for.generic.patterns>;

Note that MOVLHPSrr would be something else. It's not valid here because it's
not declared yet. I have other features for handling that. :slight_smile:

But I'm having trouble hacking tblgen to make this work. I'm not getting
variable resolution to work correctly.

I just want to know how Pat<> works right now. I can post a testcase later.

                                    -Dave

Can someone explain the magic behind the Pat<> construct and tblgen.

From X86InstrSSE.td:

def : Pat<(v4f32 (vector_shuffle VR128:$src, (undef), MOVDDUP_shuffle_mask)),
         (MOVLHPSrr VR128:$src, VR128:$src)>, Requires<[HasSSE1]>;

Where's the code in tblgen to emit the matching code for this? I'm trying to
extend it so that Pat<> can be used as a general subclass for AVX:

Hi David,

The secret here is that the 'pattern in instruction' syntax is just shorthand for a pat pattern, and tblgen internally converts all instructions into Pat pattern form. The only code to match patters handles the Pat syntax.

class Base<dag pat, dag result, ...> : Pat<dag, result> ...;

multiclass foo<dag pat, dag result, ...> {
def A : Base<pat, result, ...>;
def B : Base<pat, result, ...>;
}

I think this would just work if you end up with something like this:

multiclass foo<dag pat, dag result, ...> {
def A : Pat<result, ...>;
def B : Pat<result, ...>;
}

If the defs end up deriving from Pat, they should be automatically picked up by the existing code.

-Chris