View variable-register map

Hello everyone,

I have started using LLVM only recently, so I'm a kind of a newbie. I'm using it to observe the effects of our path-sensitive analysis of the source code on register allocation.

I just wish to know if other than manually comparing the llc generated code with the source program, is there any other way of knowing which variables in the program are mapped to which registers? I was not able to find any suitable option for the same, so I'm wondering if there is a workaround.

Thank you!

Isn't this exactly one of the things debug information is for?
You'd need to compile with -g and somehow read the DWARF information
generated. As a bonus, this should work with gcc output too.

You'd still be comparing llc output with the source code[1], but you
no longer need to do it manually :).

[1]: Or the clang AST, I suppose.

Thank you Frits! I noticed the following lines in the dwarf output (run with -O2):

     .uleb128 40 # Offset
     .byte 134 # DW_CFA_offset + Reg (6)
     .uleb128 4 # Offset
     .byte 135 # DW_CFA_offset + Reg (7)
     .uleb128 3 # Offset
     .byte 131 # DW_CFA_offset + Reg (3)

I think this is the closest to some sort of register "mapping", that I *think* changes wrt to the live intervals in the program. But there is no information about variables to which the registers are mapped.

Actually, it's fine because I don't necessarily need the variable-register map. Even the number of registers used would suffice, which I can obtain from the above. But, can you just confirm if this is the result of register allocation and that the "Reg (#)" lines represent the different registers used?

Thank you once again!

Vijay

Thank you Frits! I noticed the following lines in the dwarf output (run with
-O2):

.uleb128 40 # Offset
.byte 134 # DW_CFA_offset + Reg (6)
.uleb128 4 # Offset
.byte 135 # DW_CFA_offset + Reg (7)
.uleb128 3 # Offset
.byte 131 # DW_CFA_offset + Reg (3)

I think this is the closest to some sort of register "mapping", that I
*think* changes wrt to the live intervals in the program. But there is no
information about variables to which the registers are mapped.

There should be an encoding of variable names somewhere. I don't
really know how to read debug info myself though, so I'm not sure
where exactly.
There's probably some library that can help though. A quick bit of
googling points to libdwarf:
<http://reality.sgiweb.org/davea/dwarf.html&gt;

Actually, it's fine because I don't necessarily need the variable-register
map. Even the number of registers used would suffice, which I can obtain
from the above. But, can you just confirm if this is the result of register
allocation and that the "Reg (#)" lines represent the different registers
used?

Like I said, I don't really know how to read DWARF. But maybe someone
else on this list can enlighten you?