[LLVMdev] Pat<> & tlbgen

David Greene dag at cray.com
Tue Nov 3 15:47:50 PST 2009


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.  :)

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




More information about the llvm-dev mailing list