[LLVMdev] Transforming ConstantExprs to Instructions

Chris Lattner sabre at nondot.org
Tue Jun 17 13:14:38 PDT 2008


On Tue, 17 Jun 2008, Matthijs Kooijman wrote:
> I've been struggling with constantexprs for a bit. I'm working on a pass that
> transforms global variables to local variables, and in particular the
> GetElementPtrConstantExpr is a bit troublesome. For my transformation to
> properly work, a global value should only be used by Instructions, not by
> ConstantExprs.

Ok, this is not possible in general though, global variable initializers 
have to be constants, not instructions.

> I was thinking to add a ConstantExpr::replaceWithInstr() virtual method, which
> translates all of the uses of a constantexpr with their Instruction
> equivalents, whenever possible. Each of the subclasses of ConstantExpr can
> implement this as appropriate. Or, thinking of it, it's probably better to
> have a protected and virtual replaceUseWithInstr method which is called for
> each use by replaceWithInstr().
>
> Is this a useful addition? Is this a sane approach?

Is it possible to design the pass to work with both?  The general approach 
is to make stuff handle "User"s instead of Instructions.  It is much more 
compile time efficient to just handle the two forms rather than converting 
them back and forth.

-Chris

-- 
http://nondot.org/sabre/
http://llvm.org/



More information about the llvm-dev mailing list