[LLVMdev] Optimization - Converting Globals to Constants
andrewl at lenharth.org
Wed Jun 16 05:54:22 PDT 2010
On Tue, Jun 15, 2010 at 11:20 PM, Eli Friedman <eli.friedman at gmail.com> wrote:
> 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.
Since you know they are constant, this might be easiest for you. LLVM
should do it if your program has a main, you run internalize, you
write to them before any reads, and you don't pass them by address.
But since you are compiling the script, it is more certain to do it
there (but the more you avoid taking the address of globals, the
better the optimizer deals with them).
More information about the llvm-dev