[LLVMdev] Optimization - Converting Globals to Constants
eli.friedman at gmail.com
Tue Jun 15 21:20:19 PDT 2010
On Tue, Jun 15, 2010 at 8:49 PM, Curtis Faith <curtis at curtisfaith.com> wrote:
> It strikes me that with LLVM it ought to be possible to convert the variables to constants as part of an optimization pass that is run just before starting a simulation, or perhaps with a custom pass that I'll have to write myself. After the variables are converted to constants in the IR, it seems like further optimization could result in considerable speed increases for certain kinds of expression evaluation.
> Is there some relatively easy way to do the conversion of global floating point variables to floating point constants after loading the bitcode? Or will I have to write a custom pass to do this? It seems like the Global Variable Optimizer pass should do what I want if I set things up properly. Is that right? If so, what do I need to do to give the variables an initial value and make sure that the Global Variable Optimizer can recognize that these variables can indeed be optimized into constants?
You'll essentially have to do it yourself, I think, but it's not hard:
just call GlobalVariable::setInitializer and
GlobalVariable::setConstant on the globals in question once the
bitcode is loaded, then run instcombine to propagate the constants. I
don't think globalopt has enough information in your situation to do
the optimization in question.
More information about the llvm-dev