[cfe-dev] Adding a new pragma to Clang

Renato Golin renato.golin at linaro.org
Mon Jan 6 07:30:24 PST 2014

On 6 January 2014 15:12, Alp Toker <alp at nuanti.com> wrote:

> Pragmas in clang are monolithic with their own parse rules and state
> management so it's a bit of work. As such it's better to come up with a
> plan to support different kinds of optimization flags beyond just
> vectorization that may be needed in future, and ideally to reuse an
> existing format if a sane one exists.

Hi Alp,

I'd love to re-use pragma optimize, is it implemented already? I have to
say, this is well beyond my knowledge in Clang to do it myself, if not.

I'm already out of my way to get the vectorize pragmas in Clang, TBH... :(

#pragma clang optimize push
> #pragma clang optimize "-vectorize-loops"
>     while (...) { }
> #pragma clang optimize pop

This will only work for the first pragma, "vectorize on/off".

We have a list of other pragmas that need implementing, such as:
 1. width(N)
 2. unroll(N)
 3. safe-program-order-dist(N)
 4. safe-any-program-order
 5. safe-any-order

The first two are available as metadata already in IR, the rest have not
been completely discussed and agreed on their semantics.

We should be able to combine any number of pragmas, with local context
overriding global, etc. But this is far too distant in the future. The main
target now is to get vectorize, width and unroll done at a loop level,
since this is the only thing that is used in IR today.

Or closer to the Microsoft pragma*:
> #pragma clang optimize("vectorize-loops", on)
>     while (...) { }
> #pragma clang optimize("vectorize-loops", off)

One would hope that, regardless of the syntax, both representation on the
AST and therefore in IR, would be exactly the same.

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

More information about the cfe-dev mailing list