Inserting comments

Hi

Anyone have any clever way of inserting a comment (or
comment-ish-thing) that will make it to an .ll that's generated at the
same time as writing out the bitcode?

I'd been hacking comments in using an alloca with the name of the
value being the comment, but just realized that they weren't getting
removed at the codegen level despite being unused (no opt), when I got
a stack overflow due to having them in a loop.

I tried a no-op bitcast, but that gets removed too early, and doesn't
make to the .ll. I don't especially care if they disappear after
running passes, just that they survive long enough to see them in a
dump(), and that they don't affect the program behaviour.

thanks,
scott

Hi

Anyone have any clever way of inserting a comment (or
comment-ish-thing) that will make it to an .ll that's generated at the
same time as writing out the bitcode?

I'd been hacking comments in using an alloca with the name of the
value being the comment, but just realized that they weren't getting
removed at the codegen level despite being unused (no opt), when I got
a stack overflow due to having them in a loop.

I tried a no-op bitcast, but that gets removed too early, and doesn't
make to the .ll. I don't especially care if they disappear after
running passes, just that they survive long enough to see them in a
dump(), and that they don't affect the program behaviour.

Try using llvm.var.annotation intrinsic.

Thanks for the suggestion. I'd tried doing that by annotating a null,
but then at each "comment" point I get:

  call void @llvm.var.annotation( i8* null, i8* getelementptr ([16 x
i8]* @comment4852, i32 0, i32 0), i8* null, i32 0 )

Slightly useful, but then you have to hunt down the definition of
"@comment4852" which isn't great.

... Oh, but llvm.annotation.* is workable (ignoring the unique-ing
append of "14"):

  %"------- my comment here14" = call i8 @llvm.annotation.i8( i8 0, i8*
null, i8* null, i32 0 ) ; <i8> [#uses=0]

Thanks!

Oops, that was poorly tested. llc (targeting x86) dies with "Cannot
yet select: intrinsic %llvm.annotation". Is that because I'm using it
strangely with 0/nulls, or just some unfinished code? (I'm on 2.3
still)