[LLVMdev] conversion from 'const llvm::Value*' to 'llvm::Constant*'

Reid Kleckner reid.kleckner at gmail.com
Sun Feb 13 08:55:45 PST 2011


On Sun, Feb 13, 2011 at 11:35 AM, Anton Skvorts <anton.skvorts at gmail.com> wrote:
> Oh, I thought that after "codegening" cos(0) would get me double 1.0

Your codegen method looks like it will generate code to evaluate
cos(0).  There's no way in LLVM to run this code at global scope, it
has to be inside a function.  If you want to support running arbitrary
code at global scope in your language, you probably want to do
something like what C++ does for static initializers, where you run
code before main and fill in the values of global variables.

> (assigment is working for anything like: global a = 1/3 + 2 /3 for
> example)

The reason 1/3 + 2/3 works is because the IRBuilder recognizes these
as constants for you and folds them down to an LLVM Constant.

Reid



More information about the llvm-dev mailing list