LLVM IR Code Annotation

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

LLVM IR Code Annotation

Griffin Wright-2
Hello,

I am working on an LLVM pass which, among other things, selectively duplicates instructions in a program. 

This results in a few new instructions added to the final IR to facilitate checking, and I'd like to annotate the generated code file with a comment or something like it that would indicate that a given specific instruction has some certain property.  Essentially, just printing out flag values in a comment form in the final bitcode file that I could see when looking at the .s file generated with llc.

How could I go about doing this?

Thanks,
Griffin Wright

_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: LLVM IR Code Annotation

Devang Patel
Hi Griffin,

On Oct 4, 2011, at 8:01 AM, Griffin Wright wrote:

> Hello,
>
> I am working on an LLVM pass which, among other things, selectively duplicates instructions in a program.  
>
> This results in a few new instructions added to the final IR to facilitate checking, and I'd like to annotate the generated code file with a comment or something like it that would indicate that a given specific instruction has some certain property.  Essentially, just printing out flag values in a comment form in the final bitcode file that I could see when looking at the .s file generated with llc.
>
> How could I go about doing this?

The way I see it, you need a way to attach and preserve your annotation with an LLVM instruction, carry the annotation to corresponding MachineInstr and finally print the annotation in output .s file as a comment.

One way to do this would be:
1) Create a MDString for your comment and attach it to an LLVM instruction using setMetadata()/getMetadata() interface.
2) While converting LLVM instruction, use MDString (you will have to add new data member) in MachineInstr to hold your incoming annotation.
3) While emitting .s file, update AsmPrinter to check for your annotation with each MachineInstr and emit comment appropriately.

-
Devang
_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev