@@ -779,4 +779,56 @@ def CIR_AddressPointAttr : CIR_Attr<"AddressPoint", "address_point"> {
779779 }];
780780}
781781
782+ //===----------------------------------------------------------------------===//
783+ // TypeInfoAttr
784+ //===----------------------------------------------------------------------===//
785+
786+ def CIR_TypeInfoAttr : CIR_Attr<"TypeInfo", "typeinfo", [TypedAttrInterface]> {
787+ let summary = "Represents a typeinfo used for RTTI";
788+ let description = [{
789+ The typeinfo data for a given class is stored into an ArrayAttr. The
790+ layout is determined by the C++ ABI used (clang only implements
791+ itanium on CIRGen).
792+
793+ The verifier enforces that the output type is always a `!cir.record`,
794+ and that the ArrayAttr element types match the equivalent member type
795+ for the resulting record, i.e, a GlobalViewAttr for symbol reference or
796+ an IntAttr for flags.
797+
798+ Example:
799+
800+ ```
801+ cir.global "private" external @_ZTVN10__cxxabiv120__si_class_type_infoE
802+ : !cir.ptr<i32>
803+
804+ !rec_anon_struct = !cir.record<struct {!cir.ptr<!u8i>, !cir.ptr<!u8i>,
805+ !cir.ptr<!u8i>}>
806+
807+ cir.global constant external @type_info = #cir.typeinfo<{
808+ #cir.global_view<@_ZTVN10__cxxabiv120__si_class_type_infoE, [2 : i32]>
809+ : !cir.ptr<!u8i>, #cir.global_view<@_ZTS1B> : !cir.ptr<!u8i>,
810+ #cir.global_view<@_ZTI1A> : !cir.ptr<!u8i>}> : !rec_anon_struct
811+ ```
812+ }];
813+
814+ let parameters = (ins
815+ AttributeSelfTypeParameter<"">:$type,
816+ CIR_IntOrGlobalViewArrayAttr:$data
817+ );
818+
819+ let builders = [
820+ AttrBuilderWithInferredContext<(ins "mlir::Type":$type,
821+ "mlir::ArrayAttr":$data), [{
822+ return $_get(type.getContext(), type, data);
823+ }]>
824+ ];
825+
826+ // Checks record element types should match the array for every equivalent
827+ // element type.
828+ let genVerifyDecl = 1;
829+ let assemblyFormat = [{
830+ `<` custom<RecordMembers>($data) `>`
831+ }];
832+ }
833+
782834#endif // CLANG_CIR_DIALECT_IR_CIRATTRS_TD
0 commit comments