Free Variables In a Loop.

Hi ,

I’m working on a project in which i need to find out all free variables in a loop. I need to find all variables used inside a loop and that are not declared(allocated) in the loop. I’m confused about what symbol tables to use to get hold of such variables.

Thanks,
Rohith.

Rohith Goparaju wrote:

Hi ,

   I'm working on a project in which i need to find out all free variables in a loop. I need to find all variables used inside a loop and that are not declared(allocated) in the loop. I'm confused about what symbol tables to use to get hold of such variables.

When you say "variables," are you talking about LLVM virtual registers or memory allocated by the alloca instruction?

Assuming the former, LLVM virtual registers are in SSA form, meaning that they are defined only once and that the virtual register representing the value and the instruction that generates that value are synonymous. If you want to see if an SSA value is defined within a loop, you would use the LoopInfo pass to determine if the basic block containing the instruction defining the value of interest belongs to the loop that interests you.

Information on LoopInfo can be found at http://llvm.org/doxygen/classllvm_1_1LoopInfo.html.

-- John T.

John,

Thanks, this would work. But we are interested in obtaining the instruction that defines/allocates the value of interest. Once we obtain that we can use LoopInfo pass to check whether the basic block containing that definition instruction belongs to the loop in question. Is there a method that returns the defining instruction?

Thanks,
Adarsh

In SSA form the instruction *is* the value that it generates.

Perhaps you would rather work on Clang ASTs where assignments still exist?