[LLVMdev] RFC: AVX Pattern Specification [LONG]

David Greene dag at cray.com
Thu May 7 09:38:42 PDT 2009


On Friday 01 May 2009 16:47, David Greene wrote:

> > While I agree that we want to refactor this, I really don't think that
> > we should autogenerate .td files from perl.  This has a number of
> > significant logistical problems.  What is it that perl gives you that
> > we can't enhance tblgen to do directly?
>
> Well, mainly it's because we don't have whatever tblgen enhancements we
> need. I'll have to think on this some and see if I can come up with some
> tblgen features that could help.
>
> I was writing a lot of these base classes by hand at first, but there are a
> lot of them (they tend to be very small) and writing them is very
> mechanical. So we probably can enhance tblgen somehow.  I'm just not sure
> what that looks like right now.

So I've been thinking about this some more and the major obtacle here is that
the Perl generator has a lot of X86-specific knowledge coded into it.

For example, it knows:

* "SS" instructions need to use ths XS encoding class, but only for SSE1 
  and AVX
* "SD" instructions need to use the XD encoding class, but only for SSE2 
  and AVX
* A vector instruction never uses XS or XD encoding
* A scalar instruction never uses OpSize or TB
* AVX uses rrm and mrr encoding, SSE uses rm and mr
* rrm expands to rrr and rrm encoding, rm expands to rr and rm
* mr only expands to mr, mrr only expands to mrr
* and on and on...

I'm not sure how to conveniently encapsulate all of that detailed knowledge
in a set of TableGen classes and/or feature extensions.  Basically, TableGen
would need to look at

defm ADD : 
sse1_sse2_avx_avx3_binary_scalar_xs_xd_vector_tb_ostb_node_intrinsic_rm_rrm<
  0x58, "add", fadd, "add", 1
>;

and understand all of the SS/PS/SD/PD/VEX/etc. combinations that implies.  Or 
at least have support to conveniently express inheritance from multiclasses
that provide the valid SS/PS, etc. combinations and (this is critical) a 
convenient way to transform class/multiclass arguments to specialize them for 
the various instruction sets/encodings.  If we only want to specify patterns 
and arguments once, we need a way to specify transformations on them and pass 
the results down to base (multi)classes.  

That's what the intermediate classes generated by the Perl script do.  They
serve two functions:

* Provide valid format combinations (e.g. SS/PS/SD/PD, SS/SD, PS/PD, etc.)
* Provide argument transformation to specialize for various formats and 
  encoding

I've got a few ideas rolling in my head but I need to do some more thinking.

Oh, and I guess I'll go ahead and add XOP support too:

http://forums.amd.com/devblog/blogpost.cfm?threadid=112934&catid=208

                                -Dave



More information about the llvm-dev mailing list