[cfe-dev] Define new pragma in Clang

Daniel Dunbar daniel at zuster.org
Thu Dec 10 10:55:04 PST 2009

On Thu, Dec 10, 2009 at 7:26 AM, Alex <xinfinity_a at yahoo.com> wrote:
> Hi all,
> I would like to ask whether you can provide some information or a link to any
> documentation regarding the definition of custom pragma in Clang. I understand
> that the steps are modifying the parser lib/Parse/ParsePragma.cpp, adding an
> action in include/clang/Parse/Action.h and a handler in Sema. But it is not as
> easy as it sounds.

What exactly are you having trouble with? Generally the pragma parser
just handles the parsing logic of the pragma, and then calls a handler
in Sema which will mark some information in the AST (for example,
adding an attribute or setting a bit in the decl).

 - Daniel

> What I want is to have a pragma in the *.cpp file:
> #pragma optimizeLoop
> for(int i=0 ....)
> and to obtain the LLVM IR in the *.ll file:
> bb1:
>  %0 = load i32* %i, align 4, !pragma !0
> ...
> !0 = metadata !{metadata !"optimizeLoop"}
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev

More information about the cfe-dev mailing list