[LLVMdev] How to handle global variables in LLVM analyses
Michael Ilseman
michael at lunarg.com
Tue Oct 25 09:33:27 PDT 2011
> 1) Is there any pass to convert these simple cases to SSA form?
Mem2Reg[1] has always worked for me for globals that are only used in
one function. If this doesn't work straight away, have you tried
mem2reg after running instcombine and simplify-cfg? It's possible
those passes can sink the store. Also note that for 2.9, I believe the
default AA is no-aa, and not basic-aa, so you may be met with more
success if you specify which AA you want before you run your passes.
If none of these work for you, try making sure you're specifying a
TargetData.
If this still doesn't work, hopefully someone else has some suggestions.
[1] http://llvm.org/docs/Passes.html#mem2reg
On Mon, Oct 24, 2011 at 6:48 PM, Jorge Navas <navas at comp.nus.edu.sg> wrote:
>
> 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(){
> if(*)
> i=2; // store i32 2, i32* @i, align 4
> else
> 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.,
> "-globalsmodref-aa"?
>
> 3) Or, do I have to write a transformation pass to extend the SSA
> algorithm for my particular purpose?
>
> Thanks,
> Jorge
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
More information about the llvm-dev
mailing list