[cfe-dev] Define new pragma in Clang

Daniel Dunbar daniel at zuster.org
Mon Dec 14 17:56:38 PST 2009


On Sat, Dec 12, 2009 at 3:13 PM, Alex <xinfinity_a at yahoo.com> wrote:
> Daniel Dunbar <daniel at ...> writes:
>
>
>> 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"}
>
> My question is how can I attach the pragma to the following 'for' loop? What
> should I set in the AST such that I can translate it in the metadata in the LLVM
> IR?

Generally you would need to do something like:
 1. Add a pragma handler, which has a callback on the actions interface.
 2. Add a sema implementation of the callback, which sets some
internal bit in the Sema object.
 3. Add a new bit to the 'for' statement, to specify whether this it
had #pragma optimize set.
 4. Modify codegin to emit the metadata based on that bit.

 - Daniel

> Thank you.
>
>
> _______________________________________________
> 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