[cfe-dev] RFC: User-directed code transformations with #pragma clang transform

Michael Kruse via cfe-dev cfe-dev at lists.llvm.org
Wed Feb 19 12:11:11 PST 2020


Am Mi., 19. Feb. 2020 um 13:45 Uhr schrieb Brian Homerding <homerdin at gmail.com>:
> Thanks for the RFC!  While I see that the identifier is needed to be able to apply transform directives to new loop (which is an important capability), I'm wondering if the identifier is meant to generically separate the source location from the optimization directive.  Will I be able to add identifiers to my loops and have the optimization directives live elsewhere?  If that is the case, then the ordering of the transformations could be difficult to understand.

The identifiers also disambiguate the transformation order because a
loop can only be 'consumed' by a transformation. Any transformation
that should apply to after the the first transformation must use a
different loop name. That is,

#pragma clang transform unroll on(myloop)
#pragma clang transform vectorize on(myloop)
...
#pragma clang transform id(myloop)
for (int i = 0; i < n; ++i)
  Body(i);

is a compiler error since that transformation order is ambiguous.
Instead, only one of the transformations applies on myloop, while the
output of that transformation must be given a new name:

#pragma clang transform unroll on(mysimdloop)
#pragma clang transform vectorize on(myloop) apply(vectorized:id(mysimdloop))

In which order the pragmas appear in the source code is up to the
programmer. I hope they try to do it in a way that improved
understandably but I think misinterpreting the transformation order is
a lesser concern.


Michael


More information about the cfe-dev mailing list