[LLVMdev] Not allowed to reuse variables?
Chris Lattner
sabre at nondot.org
Wed May 5 10:20:02 PDT 2004
On Wed, 5 May 2004, Misha Brukman wrote:
> On Wed, May 05, 2004 at 03:35:46PM +0200, Anders Alexandersson wrote:
> > %tmpFunction = load int ()** %puts_kernelPTR
> > ...
> > %tmpFunction = load int ()** %puts_kernelPTR
> >
> > generates
> >
> > Redefinition of value named 'tmpFunction' in the 'int () *' type plane!
> >
> > Is it not allowed to reuse variables? Is there some way to do it?
>
> If this is in a loop and you MUST use the same variable name, then what
> you need is a 'phi' node which merges multiple values across control
> flow edges into one variable. An example: if you compile this function
Note that if you're working on a front-end though, that you shouldn't
worry about creating PHI nodes at all. Typically you should just stack
allocate any variables that can be modified, and use load/store
instructions to access them. The LLVM optimizer will promote the stack
locations to SSA form (registers) for you.
Thus, if you have code like this:
X = A + B;
You should generate code that looks like this:
%X = alloca int
...
%tmp1 = load int* %A
%tmp2 = load int* %B
%tmp3 = add int %tmp1, %tmp2
store int %tmp3, int* %X
Note that this is really ugly, but is usually all eliminated by the
optimizers, and makes the front-end much easier to handle. :)
-Chris
--
http://llvm.cs.uiuc.edu/
http://www.nondot.org/~sabre/Projects/
More information about the llvm-dev
mailing list