[llvm-dev] API to Differentiate between SSA and non SSA form

Pushpinder Singh via llvm-dev llvm-dev at lists.llvm.org
Wed Apr 19 08:50:20 PDT 2017


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


More information about the llvm-dev mailing list