LLVM Pragma

Hi everyone,

I’m using clang to emit LLVM IR of a generic C code. How can I implement a new pragma (for a loop) in clang? Is it possible to see any information for the added pragma (pragma parameters and type) at LLVM IR code?

Thank you!

I once implemented a new pragma and found the following tutorial very helpful: CES / clang-custom-pragma · GitLab

I hope this helps!

1 Like

Thank you so much Kai!
Do you know if there is a way to see the information of the custom pragma at the IR level?

If you look at the tutorial, you will find the code lines

MDNode* N = MDNode::get(C, MDString::get(C, result));
inst_final->setMetadata("quality", N);

which generate a metadata node and attach it to the given instruction. If you e.g. dump the IR of the module you compile, you will see the corresponding metadata in the module as information beginning with !.

1 Like