code gen variable mapping

Since variables in the source code are renamed in the IR, I wanted to ask you how and where this mapping is done in Clang.

I am interested in converting the variable names in some C strings to the one in the IR.

For example if at a certain point of the program I have a string like “x>0” I want to change it in “%x>0” (I already implemented a parser to recognize the identifiers so I only need to translate the name).

If you have any suggestion in how to do it easily (like if there is already a data structure or a method to call) it will be really appreciated.

this is essentially hopeless. Most names in LLVM IR have no meaning, they are
just there to make debugging easier: they can be removed altogether and all will
still work fine. Even if the front-end is kind enough to set a name, optimizers
can change them. Why do you want this name mapping? Maybe you should be using
debug info instead?

I am interested in using the information a programmer can put in some annotation comments in order to improve the optimization on the source code.
Since the programmer will write those annotations using the source code names, I need to find a way to carry on these comments in the IR generation in order to make them available for later optimization passes.
I thought about attaching those comment as a metadata string to the next instruction after the comment.
I am new to LLVM and by reading the .s output files I thought that clang does some kind of renaming to the variables.
Do you think there is an easier way to do that?

Thank you again,

Niko

Since variables in the source code are renamed in the IR, I wanted to ask
you how and where this mapping is done in Clang.

I am interested in converting the variable names in some C strings to the
one in the IR.

For example if at a certain point of the program I have a string like "x>0"
I want to change it in "%x>0" (I already implemented a parser to recognize
the identifiers so I only need to translate the name).

If you have any suggestion in how to do it easily (like if there is already
a data structure or a method to call) it will be really appreciated.

this is essentially hopeless. Most names in LLVM IR have no meaning, they
are
just there to make debugging easier: they can be removed altogether and all
will
still work fine. Even if the front-end is kind enough to set a name,
optimizers
can change them. Why do you want this name mapping? Maybe you should be
using
debug info instead?

I am interested in using the information a programmer can put in some
annotation comments in order to improve the optimization on the source code.
Since the programmer will write those annotations using the source code
names, I need to find a way to carry on these comments in the IR generation
in order to make them available for later optimization passes.

If you parse the annotations & actually form references to the
original variables, you may be able to maintain that mapping during
Clang's IRGen, lowering your annotations into something LLVM can work
with (probably in some sort of LLVM metadata).