Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

clang adding a new pragma

I want to know which all llvm IR statements correspond to the code inside a particular pragma in clang. My pragma is having the following structure.

#pragma markme
{
   stmt1;
   stmt2;
}

I need to know which all stmts were present between the opening braces and closing braces of mark me pragma.

Can we attach some metadata to these stmts? If yes could anyone point me to some reference.

I have searched on Google and found this

Add a pragma handler, which has a callback on the actions interface. Add a sema implementation of the callback, which sets some internal bit in the Sema object. Add a new bit to the 'for' statement, to specify whether this it had #pragma optimize set. Modify codegin to emit the metadata based on that bit.

Could any one give more details on this.

I am using the latest llvm (llvm 3.4)

Note: Any help in any direction is appreciated. I know llvm may do optimizations that moves the statements around. But this is fine with me

like image 735
simpleuser Avatar asked Mar 23 '23 01:03

simpleuser


1 Answers

Note that this has to be done in Clang, which knows about #pragma. LLVM itself knows nothing about them - #pragma are not part of the LLVM IR.

There are plenty of examples of generating metadata in Clang's lib/CodeGen directory. It all depends on where you want this metadata to appear - on instructions? On functions?

For attaching metadata to instructions look for setMetadata. For example, in lib/CodeGen/CGExpr.cpp, some profiling metadata is attached to branches. For placing module-level metadata, see lib/CodeGen/CodeGenModule.cpp.

like image 186
Eli Bendersky Avatar answered Apr 01 '23 15:04

Eli Bendersky