[LLVMdev] How to handle global variables in LLVM analyses

Jorge Navas navas at comp.nus.edu.sg
Mon Oct 24 17:48:36 PDT 2011

I'm trying to implement a basic analysis for inferring the ranges
(minimum and maximum values) of integer variables. I don't expect for
now to reason about pointers or arrays but I would like some reasoning
about global variables.

As expected, the fact that all register values are in SSA form
simplifies a lot the analysis. However, global variables are not
necessarily in SSA form. I understand the reasons but I wonder what I
can do for simple cases like this one:

int i;                       
void foo(){                  
       i=2;   // store i32 2, i32* @i, align 4
       i=3;   // store i32 3, i32* @i, align 4

Here I would like to have a phi-node after the if-then-else so my
analysis can easily merge the values 2 and 3 for the global variable
"i". I guess, this is a common case (no aliasing, no function
pointers, etc) so i wonder what is the way to go:

1) Is there any pass to convert these simple cases to SSA form?

2) Alternatively, can I extract some useful info from e.g.,

3) Or, do I have to write a transformation pass to extend the SSA
   algorithm for my particular purpose?


More information about the llvm-dev mailing list