I wondered if there was a standard way in LLVM to replace a constant with a variable. The standard replaceAllUsesWith does not work because other constants may use the constant-to-be-replaced. I would like to recursively replace these by the corresponding expression.
Any ideas? Thanks,
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,