[LLVMdev] Reducing .td redundancy

David Greene dag at cray.com
Tue Mar 24 10:04:25 PDT 2009


On Tuesday 24 March 2009 10:43, Chris Lattner wrote:
> On Mar 23, 2009, at 5:56 PM, David Greene wrote:
> > Is it legal to do something like a !strconcat on a non-string
> > entity?  That
> > is, is there some operation that will let me do this (replace
> > SOME_CONCAT with
> > an appropriate operator):
>
> I don't get it, can you try a simpler example on me? :)

Ok, let see if I can construct something.

>From the IntrinsicsX86.td file:

  def int_x86_sse_add_ss : GCCBuiltin<"__builtin_ia32_addss">,
              Intrinsic<[llvm_v4f32_ty, llvm_v4f32_ty,
                         llvm_v4f32_ty], [IntrNoMem, Commutative]>;

  def int_x86_sse2_add_sd : GCCBuiltin<"__builtin_ia32_addsd">,
              Intrinsic<[llvm_v2f64_ty, llvm_v2f64_ty,
                         llvm_v2f64_ty], [IntrNoMem, Commutative]>;

Untested multiclass!  Look for SOME_CONCAT.

multiclass myintrinsics<bits<8> opc, string OpcodeStr, Intrinsic Intr> {
   // Scalar intrinsics
  def SSrr_Int SSI<opc, MRMSrcReg, (outs FR32:$dst), (ins FR32:$src1, FR32:
$src2),
                 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
                 [(set FR32:$dst, (SOME_CONCAT(Intr, _ss) FR32:$src1, FR32:
$src2))]> {

  def SDrr_Int SSI<opc, MRMSrcReg, (outs FR64:$dst), (ins FR64:$src1, FR64:
$src2),
                 !strconcat(OpcodeStr, "ss\t{$src2, $dst|$dst, $src2}"),
                 [(set FR32:$dst, (SOME_CONCAT(Intr, _sd) FR32:$src1, FR32:
$src2))]> {
}

defm ADD : myintrinsics<0x58, "add",  int_x86_sse2_add>;

I want the single ADD defm to generate patterns for both the "ss" and "sd" 
intrinsic variants.  I need a way to append "_ss" or "_sd" to the intrinsic 
name in the pattern.

I don't believe there's any way to do this right now but I'm looking into it.  
I'm currently stepping through TableGen to figure out when pattern fragments
(which get instantiated as CodeInits if I understand correctly) have their
arguments substituted.  At that point I want to scan the pattern and look
for special concat operations and munge the resulting strings / names / 
whatever to do the right thing.  Any hints on where to look?

                                         -Dave





More information about the llvm-dev mailing list