[LLVMdev] Using annotation attributes

Tanya M. Lattner tonic at nondot.org
Thu Jun 5 12:04:17 PDT 2008


> I'm trying to annotate certain functions in C code, and do something with
> these functions in my LLVM pass. I annotate the C code like this:
>
> int __attribute__((annotate("annot"))) function() {
>
> This nicely gets added to the LLVM bitcode in an
> @llvm.global.annotations global. Now I had hoped that it'd be easy to extract
> a list of functions annotated with my annotation using
>
> AnnotationManager::getID("annot")
> and later on:
> function->getAnnotation(AnnotID).
>
> This does not seem to work, unfortunately. Is this supposed to work in this
> way, or am I using the wrong functions? I could of course just try to
> manually parse the @llvm.global.annotations constant, but that seems rather
> tiresome :-)

There is no way to get it from the Function*. You have to get the global 
annotations array and parse it yourself. You could easily write a pass to 
do this for you and store it in a map.

I think the main reason is that we don't want to bloat the IR by making 
space for annotations in the Function itself.

-Tanya



More information about the llvm-dev mailing list