[LLVMdev] named types with self-references
Jianzhou Zhao
jianzhou at seas.upenn.edu
Thu Nov 11 09:37:42 PST 2010
On Thu, Nov 11, 2010 at 12:11 PM, Chris Lattner <clattner at apple.com> wrote:
>
> On Nov 11, 2010, at 8:45 AM, Jianzhou Zhao wrote:
>
>> Hello,
>>
>> Can I define a named type ? %rt = {%rt}
>> llvm-as can parse this definition without errors.
>>
>> JIT executes '%0 = alloca %rt' as allocating a memory with size 0.
>> Because the llvm::TargetData::getTypeAllocSize accually returns 0 in
>> this case. The function that calculates %rt's size is by the
>> TargetData::getStructLayout, which calculates the a layout of %rt. It
>> can only returns 0 when the element type %rt is not defined yet, since
>> the result is infinite otherwise.
>>
>> Is %rt = {%rt} still a valid or useful type for LLVM IR?
>
> No, that's not (or shouldn't be) a valid type. In this case, zero bytes is correct, but something like %rt = {%rt,i8} has infinite size.
I tried %rt = {%rt,i8}, Its type size is 1. Does ' infinite size' mean
the getTypeAllocSize function may not terminate? I am still using
2.6, whose getStructLayout stops, and assigns 1 as StructSize. Will
2.8 return a larger number?
We could even define
%rt = {%rt}
%rt1 = {%rt2}
%rt2 = {%rt1}
and LLVM can eventually unify all of them to be %rt. If these %rt are
not valid, will any pass of LLVM check and report such types, or this
is supposed to be a requirement of frontends?
>
> -Chris
--
Jianzhou
More information about the llvm-dev
mailing list