Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add comments to LLVM IR?

Tags:

llvm

Is it possible to add comments into a BasicBlock? I only want that when I print out the IR for debugging I can have a few comments that help me. That is, I fully expect them to be lost once I pass them to the optimizer.

like image 733
edA-qa mort-ora-y Avatar asked Oct 23 '13 03:10

edA-qa mort-ora-y


Video Answer


1 Answers

No, it's not possible directly. Comments, by which you probably mean the lexical elements beginning with a semicolon (;) in the textual IR representation, have no representation in the in-memory IR (and binary bitcode). As you probably know, LLVM IR has three equivalent representations (in memory API level, textual "assembly" level, binary bitcode level). Once the LLVM assembly IR parser reads the code into memory, comments are lost.

What you could do, however, is use metadata for this purpose. You can create arbitrary metadata attached to any instruction, as well as global module-level metadata. This is a hack, for sure, but if you really think you need some sort of annotation, metadata is the way. LLVM uses metadata for a number of annotation needs, like debug info and alias analysis annotations.

like image 195
Eli Bendersky Avatar answered Oct 23 '22 01:10

Eli Bendersky