[LLVMdev] Enhacing TabelGen

David A. Greene greened at obbligato.org
Thu Oct 6 10:01:58 PDT 2011


greened at obbligato.org (David A. Greene) writes:

> Also, I know I introduced the #..# "pasting" operation but I've found it
> to be too limiting.  In this example:

[snip!]

> what if we instead did this:
>
> (Equivalent TableGen code with a for-loop)
> ----------------------------------------
> multiclass PTX_FLOAT_4OP<string opcstr, SDNode opnode1, SDNode opnode2> {
>   for nbit         = [32, 32, 64, 64],
>       op_suffix    = [r, i, r, i],
>       op_type      = [RegF32, f32imm, RegF64, f64imm],
>       op_node_type = [RegF32, fpimm, RegF64, fpimm] in {
>     def !strconcat(!strconcat("rr", !cast<string>(op_suffix)), "nbit")
>       [...]
>   }
> }
>
> Yes, it's a bit more verbose but also more flexible in what you can do
> with iterator values.

Here's some more detail on this.

I want to be able to use #..# pasted stuff in a variety of contexts.
For example:

multiclass blah<string intr> {
  for prefix = [<empty>, Vx, Vy] {
    for suffix = [ps, pd] {
      def #prefix#ADD#suffix# : ProcessSomePattern<
        [(set RegClass:$dst, (!cast<Intrinsic>(#prefix#intr#suffix)
                              RegClass:$src1, RegClass:$src2))]
    }
  }
}

It's actually more complex than this but this gives the basic idea.  The
key thing I need to be able to do is construct an instrinsic name given
some base string, a prefix and a suffix.

Here's a critical question.  What type do the for loop iterators have?
string?

If the iterators are strings, I know that this will work:

!cast<Instrinsic>(!strconcat(!strconcat(prefix, intr), suffix))

Will this work as well?

!cast<Intrinsic>(#prefix#intr#suffix)

If so, I think I can get away with using #..#.  If for loop iterators
are typed as strings that would also allow me to do what I need via
strconcat.

Actually, having both iterators as strings and paste "operator" results
as strings would be useful.

                                -Dave



More information about the llvm-dev mailing list