[llvm-dev] Adapting TableGen

Martin J. O'Riordan via llvm-dev llvm-dev at lists.llvm.org
Thu Jun 16 06:10:04 PDT 2016


I have a large number of instruction patterns that involves a lot of
replication in TableGen.

 

To reduce this replication I want to use 'foreach', but in this case the
action is operating on 'multiclass' and 'defm'.  Basically I want to make
the following work:

 

    foreach item = { "ReplA", "ReplB", ... , "ReplZ" } in {

      defm PRE_#item#_POST : BASE_#item#_SUFF<.....>;

    }

 

Unfortunately TableGen doesn't handle this for 'multiclass' and 'defm', so I
have made adaptations to 'lib/TableGen/TGParser.*' that would allow this to
happen.  In this code I have a variable 'idFragment' that represents the
iteration variable name for the 'foreach' loop.  Next I want to perform the
substation, but I can see how I get the current value to perform the
replacement.  My code is:

 

    for (ForeachLoop var: Loops) {

      if (var.IterVar->getName() == idFragment) {

 

but having identified where to perform the replacement, I can't find how to
get the current value to replace 'item' with {e.g. is it 'ReplF'?}

 

Any hints on how I can do this?  The normal replacement code I find very
hard to follow.

 

Thanks,

 

            MartinO

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160616/dc59a6fc/attachment.html>


More information about the llvm-dev mailing list