Hi folks,
TableGen provides sufficiently rich syntax for expressing target
instruction set. Nevertheless, when I wrote the PTX backend, I
observed that some redundancy in TableGen can be further eliminated
through macro expansion of for-loops.
The semantics of a for-loop is expanding the for-loop body, and so it
is equivalent to manually unroll the loop (see example #1).
I believe the for-loop is not only useful to the PTX backend but also
to other backends (see examples below). Generally speaking, a for-loop
can be used anywhere when you see a "table filling" pattern --- you
are writing repeated identical lines that only differs in a few places
(see examples below).
An (illustrative, not complete) BNF of for-loop is as follows: