[cfe-dev] Adding a new pragma to Clang

Alp Toker alp at nuanti.com
Mon Jan 6 07:12:04 PST 2014

Hi Renato,

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.

One possibility is to re-use the #pragma clang diagnostic machinery, and 
along with it the command line parser. It has a lot of the work covered 
to track source locations, on/off states that you're better of not 

It'd give us something like:

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

Or closer to the Microsoft pragma*:

#pragma clang optimize("vectorize-loops", on)
     while (...) { }
#pragma clang optimize("vectorize-loops", off)

gcc* has some interesting pragmas in this space already. Would any of 
those do what you need, or did you have a different grammar in mind?

* http://msdn.microsoft.com/en-us/library/chh3fb0k.aspx
* http://gcc.gnu.org/onlinedocs/gcc/Function-Specific-Option-Pragmas.html


On 06/01/2014 14:05, Renato Golin wrote:
> Hi Folks,
> I'm adding the pragma vectorize to Clang to print specific metadata on 
> loops (later any lexical block), and I'm having some trouble 
> identifying the steps.
> I've added my pragma to ParsePragma, then added a vectorizer context 
> to Sema to temporarily hold these values to be used on the next 
> lexical block (one at a time, recent replace old, style).
> But the only way I found to add this information into the AST was via 
> traits, which doesn't look correct. Can anyone point me in the right 
> direction?
> Who is the best person to review these changes?
> cheers,
> --renato
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev

the browser experts

More information about the cfe-dev mailing list