[LLVMdev] question in LLVM IR

Duncan Sands baldrick at free.fr
Mon Jan 18 01:19:45 PST 2010

Hi Joey,

>   I read LLVM manual, and have a question in the LLVM IR.
> The IR is low-level SSA based instruction set.
> I want to know what the difference between the LLVM IR and SSA form?
> They are same, similar to tree-ssa of GCC convertion GIMPLE tree to SSA 
> and convert back when optimizations finish?  
> or just attach the SSA info in the LLVM IR?

LLVM IR is always in SSA form - there is no conversion between a non-SSA
version and an SSA-version, there is only the SSA version.  Consider an
LLVM load instruction:
  %tmp = load i32* %addr
Here %addr is the pointer being loaded from, and %tmp is the loaded value.
Since LLVM IR is in SSA form, %tmp cannot be defined differently later, so
%tmp is *equivalent* to the instruction "load i32* %addr".  Thus (unlike in
GIMPLE) there is no actual assignment going on in "%tmp = ...", this textual
form is just for the benefit of human readers, and means that %tmp is the name
of the instruction on the right-hand side.  This is why you will search in vain
for an assignment instruction in the IR definition: there isn't one.  In order
to get the effect of assigning multiple times to a variable, you either need
to generate explicit phi nodes, or generate explicit stores to memory (unlike
registers like %tmp, memory is not in SSA form; this is the same as in GIMPLE).



More information about the llvm-dev mailing list