[LLVMdev] Transforming ConstantExprs to Instructions

Eli Friedman eli.friedman at gmail.com
Thu Jun 19 00:29:21 PDT 2008


On Wed, Jun 18, 2008 at 10:19 PM, Chris Lattner <sabre at nondot.org> wrote:
> What do you mean?  A constantexpr gep can be used as the size of an
> alloca.

A constantexpr as an argument to an alloca is legal, but a
constantexpr can't use an alloca.

Suppose you have a global struct, and you load the third member.  The
IL for this is something like "load i32* getelementptr ( %struct @x,
i32 0, i32 2)".  Now you want to replace the global @x with a local
alloca %x (assuming all the appropriate safety checks are done).
"load i32* getelementptr (%struct %x, i32 0, i32 2)" is illegal; it
has to be split into "%loadaddr = getelementptr %struct %x, i32 0, i32
2" and "load i32* %loadaddr".

-Eli



More information about the llvm-dev mailing list