[LLVMdev] defining types structurally equivalent to a recursive type
Chris Lattner
clattner at apple.com
Thu Nov 11 09:12:09 PST 2010
On Nov 11, 2010, at 6:45 AM, Jianzhou Zhao wrote:
> On Thu, Nov 11, 2010 at 8:28 AM, Jianzhou Zhao <jianzhou at seas.upenn.edu> wrote:
>> 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
>> }
>
> Sorry, my orginal test code is:
>
> %rt = type { %rt* }
> %rt1 = type { %rt* }
>
> define i32 @main() nounwind {
> entry:
> %0 = alloca %rt
> %1 = alloca %rt1
> %2 = icmp eq %rt* %0, %1
> ret i32 0
> }
>
> After llvm-as, llvm-dis, LLVM automatically renames all %rt1 to be
> %rt. The 'icmp' is to test if LLVM takes them to be same, since icmp
> requires operands be of same type.
Yep, that's correct behavior.
-Chris
>
>>
>> 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
>>
>
>
>
> --
> Jianzhou
>
> _______________________________________________
> 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