API to Differentiate between SSA and non SSA form

Hello everyone,

We are working on a particular points-to analysis. The final output of
that analysis should not have the LLVM SSA temporaries (like, %0, %1).
My doubt is that whether we can extract the normal C variables from
LLVM IR or is there any way to differentiate between SSA temporary and
local C variable?

For e.g. in GCC I can check whether a particular variable is an SSA
temporary like,

     if(TREE_CODE(t) == SSA_NAME)
            return true;

Basically, I want to skip all those %0, %1 temporaries. But keep all
those which refer to C variables. One way to do this would be to check
whether a Value has been given a name by using hasName function. But
it does not work every time. For e.g. in case of getelementptr
instruction, this name refers to a member name of a structure (which
is in SSA form).
E.g.,

define void @f() {
entry:
  %s = alloca %struct.A, align 8
  %a = alloca i32, align 4 ; I can know that
this is a C variable
  store i32 10, i32* %a, align 4
  %b = getelementptr inbounds %struct.A, %struct.A* %s, i32 0, i32 1
  ; but this is not
  store i32* %a, i32** %b, align 8

  ; and this is not a C variable, so hasName logic can not work here.
  %a1 = getelementptr inbounds %struct.A, %struct.A* %s, i32 0, i32 0
  store i32 30, i32* %a1, align 8
  ret void
}

Thanks,
Pushpinder Singh

Is it the case that for each C stack variable there will always be and ‘alloca’ statement. If so, we can identify all such variables.

And globals can be identified separately, I guess…

That would only hold true before the mem2reg pass, which makes the alloca
into registers whenever possible.

And conversely, the compiler may well introduce temporary allocas that
aren't referring to any variable in the source code.

I'd be surprised if there is a trivial way to tell this - more likely, you
need source-code information (e.g. AST-level) to perform such analysis.
Possibly debug info would be helpful too.

SSA does not directly map onto C variables.
C variables vary. SSA labels do not vary.
If you wish to raise LLVM to C, a general approach could take all the SSA
labels that are linked with a PHI statement, and give them all the same C
variable name.
It is unclear what you mean by "points-to analysis". You might wish to
look into "alias analysis" as it might be similar to what you are trying to
do.

The "alloca" statement can represent a C local variable, but due to
optimisations, not all C local variables are stored on the stack.