Clang Adds New Pragma

I want to know which all llvm IRL instructions correspond to code inside a specific pragma in clang. My pragma has the following structure.

#pragma markme { stmt1; stmt2; } 

I need to know what all the stmts were present between the opening brackets and the closing brackets mark me pragma.

Can we attach some metadata to these stmts? If so, can I point to some link.

I searched on google and found this

Add a pragma handler that has a callback in the action interface. Add a callback sema implementation that sets some internal bit in the Sema object. Add a new bit to the 'for' statement to indicate whether it was #pragma optimize set. Modify the code to extract metadata based on this bit.

Can anyone give more details on this.

I am using the latest version of llvm (llvm 3.4)

Note: Any help in any direction is appreciated. I know that llvm can do optimizations that move statements around. But this is normal with me.

+4
source share
1 answer

Note that this needs to be done in Clang, which knows about #pragma . LLVM itself does not know anything about them - #pragma are not part of LLVM IR.

There are many examples of metadata generation in the Clang lib/CodeGen . It all depends on where you want this metadata to be displayed - according to the instructions? What about the features?

To add metadata in the statement, find setMetadata . For example, in lib/CodeGen/CGExpr.cpp some profiling metadata is bound to branches. To place metadata at the module level, see lib/CodeGen/CodeGenModule.cpp .

+7
source

Source: https://habr.com/ru/post/1493189/


All Articles