Annotate attribute

Many of you on the llvm-dev list have requested this, so I've added a new attribute to llvm-gcc. The "annotate" attribute can be used to annotate functions, global and local variables with arbitrary strings. This can be useful for special purpose optimizations and are ignored by code generation.

For functions and global variables, the annotations are represented in a global array "llvm.global.annotations". This is an array of structs that contain four elements: pointer to the value, pointer to the string, pointer to a string which is the source file, and the line number.

Annotations for local variables use the "llvm.var.annotation" Intrinsic. This intrinsic has 4 arguments which are the same as the 4 elements in the struct for the global case.

If you would like to see an example of this, please run the following test:
lvm-gcc -c -emit-llvm test/CFrontend/2007-06-15-AnnotateAttribute.c -O -o -

llvm-dis

If you have any questions, please let me know.

Thanks,
Tanya

Hi Tanya,

In the long term, how are different uses of this string going to be
kept from conflicting? Is this going to introduce another mini-syntax
into LLVM, to allow different passes to recognize which pass the string
is intended for, or to allow passes to pull out selected substrings and
ignore the rest?

Dan

In the long term, how are different uses of this string going to be
kept from conflicting? Is this going to introduce another mini-syntax
into LLVM, to allow different passes to recognize which pass the string
is intended for, or to allow passes to pull out selected substrings and
ignore the rest?

I am also curious to know what this is intended for precisely. Couldn't
it be done using debug intrinsics instead?

Ciao,

Duncan.

In the long term, how are different uses of this string going to be
kept from conflicting? Is this going to introduce another mini-syntax
into LLVM, to allow different passes to recognize which pass the string
is intended for, or to allow passes to pull out selected substrings and
ignore the rest?

I should have clarified: This is not something that would be used in mainline llvm. This is mainly for people doing something research orientated and need the annotate attribute. If they need to prevent strings from conflicting, they would do so.

-Tanya

In the long term, how are different uses of this string going to be
kept from conflicting? Is this going to introduce another mini-syntax
into LLVM, to allow different passes to recognize which pass the string
is intended for, or to allow passes to pull out selected substrings and
ignore the rest?

I am also curious to know what this is intended for precisely. Couldn't
it be done using debug intrinsics instead?

Its intended for people doing research and need to annotate things for some special purpose. For example if someone wants to tag all the custom memory allocators. You would never see this used in mainline llvm for some optimization (they would probably create a specific attribute if needed).

It would not be a good idea to use the debug intrinsics since those are for a specific purpose and not generic like this attribute. I don't think its a good idea to overload them.

-Tanya