Hi, %_t4 = add int 23 , 0 %_t5 = add int %_t4 , 1 %_t4 = add int %_t5 , 0 the above line of code give an error when i try to convert to bytecode. The error is that I am trying to redefine %_t4. Is there a way to reassign a variable with another value. Also is there a way to assign a value to a variable. I couldnt do that so I added 0 to it ! :) Thanks Jai
On Sun, 12 Dec 2004, Jai Vasanth wrote:> Hi, > > > %_t4 = add int 23 , 0 > %_t5 = add int %_t4 , 1 > %_t4 = add int %_t5 , 0 > > the above line of code give an error when i try to convert to > bytecode. The error is that I am trying to redefine %_t4. Is there a > way to reassign a variable with another value. Also is there a way to > assign a value to a variable. I couldnt do that so I added 0 to it ! > :)No, this is Static Single Assignment form, which means there can only be one assignment to a value. If you want multiple assignment, use memory (such as a stack location). E.g.: %t4 = alloca int %_t4 = add int 23 , 0 store int %_t4, int* %t4 %_t5 = add int %_t4 , 1 %_t4 = add int %_t5 , 0 store int %_t4, int* %t4 Given (ugly) code like this, the LLVM -mem2reg pass will construct SSA for you and discard the unneeded allocas. -Chris -- http://nondot.org/sabre/ http://llvm.cs.uiuc.edu/
On Sun, 12 Dec 2004, Chris Lattner wrote:> No, this is Static Single Assignment form, which means there can only be one > assignment to a value. If you want multiple assignment, use memory (such as > a stack location). E.g.: > > %t4 = alloca int > %_t4 = add int 23 , 0 > store int %_t4, int* %t4 > %_t5 = add int %_t4 , 1 > %_t4 = add int %_t5 , 0 > store int %_t4, int* %t4*** Sorry, of course this won't work either. If you replace the last two lines with: %_t4.2 = add int %_t5 , 0 store int %_t4.2, int* %t4 It should work. -Chris -- http://nondot.org/sabre/ http://llvm.cs.uiuc.edu/
Jai, Just to add a bit of context to Chris's reply ... As he pointed out, LLVM registers are in SSA form but memory is not. You do not need to generate SSA form when generating LLVM in your front-end, because it is not straightforward to do so. Instead, you can "alloca" all variables on the stack, and use loads and stores to access their values. mem2reg will promote most such alloca variables back to registers in SSA form. If you want to generate more compact code, you can put local temporaries (from within a simple source statement) in SSA registers since they are not used outside the basic block where they are generated. For example, you could put %_t5 in a register below easily, but leave _t4 on the stack. This is not particularly important for small programs. On Dec 12, 2004, at 1:14 AM, Jai Vasanth wrote:> Hi, > > > %_t4 = add int 23 , 0 > %_t5 = add int %_t4 , 1 > %_t4 = add int %_t5 , 0 > > the above line of code give an error when i try to convert to > bytecode. The error is that I am trying to redefine %_t4. Is there a > way to reassign a variable with another value. Also is there a way to > assign a value to a variable. I couldnt do that so I added 0 to it ! > :) > > Thanks > > > Jai > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://mail.cs.uiuc.edu/mailman/listinfo/llvmdev >--Vikram http://www.cs.uiuc.edu/~vadve http://llvm.cs.uiuc.edu/