Recover variable name after mem2reg

Hi everybody,

I have some issues trying to recover the name of the variables from the metadata.
Let me explain : I have a LLVM IR file, compiled with -g, on which I apply the -mem2reg optimization pass. This pass has the effect of removing the dbg.declare function calls from the bitcode, and replaces them by calls to the intrinsic function dbg.value. However, these function calls do not allow to easily associate each of the llvm instructions to its corresponding variable name in my C code.
For instance, I don’t figure out how to recover the name in the C program of a Phi value “%x.1”, which is clearly my “x” variable in C.

Do I miss something ?

Thanks for your help.

Debug info metadata is your best bet. There's no guaranteed mapping.