[LLVMdev] defining types structurally equivalent to a recursive type

Jianzhou Zhao jianzhou at seas.upenn.edu
Thu Nov 11 05:28:58 PST 2010


Hi all,

http://www.llvm.org/docs/ProgrammersManual.html#BuildRecType suggests
us to define recursive types via opaque and refine. Since LLVM has
structural types, %rt = type { %rt* } and %rt1 = type { %rt* } should
be same structurally. I tested the following code,

%rt = type { %rt* }
%rt1 = type { %rt* }

define i32 @main() nounwind {
entry:
  %0 = alloca %rt                                 ; <%rt*> [#uses=1]
  %1 = alloca %rt                                 ; <%rt*> [#uses=1]
  %2 = icmp eq %rt* %0, %1                        ; <i1> [#uses=0]
  ret i32 0
}

In the code, LLVM unifies %rt and %rt1 to be same, and picks %rt to
represent them. If I define %rt %rt1 manually, can I first define %rt
by opaque and refine, and then define %rt1 as normal structures ---
defining %rt1 as a 'concreate' structure by Struct::Get with the
element type %rt, since %rt1 is not a recursive type 'syntatically'.
But I am wondering if I need PATypeHolder to protect %rt1. Will %rt1
be deleted if LLVM finds it is same to %rt?

Thanks.
-- 
Jianzhou



More information about the llvm-dev mailing list