[LLVMdev] Replace constant with variable

Jonas Wagner jonas.wagner at epfl.ch
Mon Jun 18 09:09:47 PDT 2012


Hi,

> why?

It's a good question. The short answer is that I'm working on a program 
analysis tool which, among other things, checks the memory accesses that 
the program performs. To do so, we have a model of the program's memory.

This memory model is quite limited and does not support global 
variables. Hence I convert those into variables that are allocated on 
the stack. Now the address of that global variable (a link-time 
constant) becomes a variable, namely the return value of an alloca 
instruction.

To replace uses of the constant by this variable address, I currently 
have a very ugly solution that involves a large switch on the OpCode of 
a ConstantExpr :-(

Any better solutions are welcome. Cheers,
Jonas



More information about the llvm-dev mailing list