[LLVMdev] Named metadata to represent language specific logic

Jin Gu Kang jaykang10 at imrc.kist.re.kr
Fri Mar 25 18:09:07 PDT 2011


Hi Renato,

I was also applying extensible metadata to my project. :)

>;====================================
>; Unions & bitfields
>; union U { int a; int b:3; int c:3; char d; }
>%union.U = type { i32 }, !union;
>!union = metadata { metadata !U.a, metadata !U.bc, metadata !U.d };
>!U.a = metadata { metadata !intID, metadata !"align", i8 4 };
>!U.bc = metadata { metadata !U.b, metadata !U.c };
>!U.b = metadata { metadata !charID, metadata !"align", i8 4, metadata
>!"size", i8 3 };
>!U.c = metadata { metadata !charID, metadata !"align", i8 4, metadata
>!"size", i8 3, metadata !"offset", i8 3 };
>!U.d = metadata { metadata !charID, metadata !"align", i8 4 };

I think type cannot have Named Metadata on current llvm code.
If you will distinguish type with Named Metadata and type without
Named Metadata, you will also have to change type system and codes
related to it. For example, To distinguish "type { i32 } !union" and 
"type { i32 }", StructValtype has to be change and then type of value 
with "type { i32 } !union" is distinguished from type of value with
"type { i32 }". This property will give confusion to related codes.

I suggest Named Metadata with all of union types as following:

%union.U = type { i32 };

!llvm.uniontypes = metadata !{!0}

!0 = metadata !{metadata !"union.U", metadata !1, metadata !2, metadata !5 };
!1 = metadata !{ metadata !intID, metadata !"align", i8 4 };
!2 = metadata !{ metadata !3, metadata !4 };
!3 = metadata !{ metadata !charID, metadata !"align", i8 4, metadata
!"size", i8 3 };
!4 = metadata !{ metadata !charID, metadata !"align", i8 4, metadata
!"size", i8 3, metadata !"offset", i8 3 };
!5 = metadata !{ metadata !charID, metadata !"align", i8 4 };

"!0" will must point to own IR type like first argument (metadata !"union.U").
Other method may be needed to point to own IR type becuase
initializer of union type sometimes has temporary type.

>;====================================
>; Class size
>; struct Base { char a[3]; Base() {} };
>; struct Derived : Base { char b; }
>%struct.Base = type { [3 x i8] }, !BasePadding;
>%struct.Derived type { %struct.Base, i8 }, !DerivedPadding;
>!BasePadding = { metadata !"size", i8 1 };
>!DerivedPadding = { metadata !"size", i8 3 };

%struct.Base = type { [3 x i8] } 
%struct.Derived type { %struct.Base, i8 };

!llvm.classtypes = metadata !{!0, !1}

!0 = !{ metadata !"struct.Base", metadata !"size", i8 1, and other informations };
!1 = !{ metadata !"struct.Derived type", metadata !"size", i8 3, and other informations };

I agree to use extensible metadata to store informations of high level
language without changing the IR. I think it is so hard working for me 
to change IR becase of a lot of side effets and compatibility.

Thanks,
Jin-Gu Kang



More information about the llvm-dev mailing list