@@ -535,6 +535,72 @@ def CIR_GlobalViewAttr : CIR_Attr<"GlobalView", "global_view", [
535
535
}];
536
536
}
537
537
538
+ //===----------------------------------------------------------------------===//
539
+ // VTableAttr
540
+ //===----------------------------------------------------------------------===//
541
+
542
+ def CIR_VTableAttr : CIR_Attr<"VTable", "vtable", [TypedAttrInterface]> {
543
+ let summary = "Represents a C++ vtable";
544
+ let description = [{
545
+ Wraps a #cir.const_record containing one or more vtable arrays.
546
+
547
+ In most cases, the anonymous record type wrapped by this attribute will
548
+ contain a single array corresponding to the vtable for one class. However,
549
+ in the case of multiple inheritence, the anonymous structure may contain
550
+ multiple arrays, each of which is a vtable.
551
+
552
+ Example 1 (single vtable):
553
+ ```mlir
554
+ cir.global linkonce_odr @_ZTV6Mother =
555
+ #cir.vtable<{
556
+ #cir.const_array<[
557
+ #cir.ptr<null> : !cir.ptr<!u8i>,
558
+ #cir.global_view<@_ZTI6Mother> : !cir.ptr<!u8i>,
559
+ #cir.global_view<@_ZN6Mother9MotherFooEv> : !cir.ptr<!u8i>,
560
+ #cir.global_view<@_ZN6Mother10MotherFoo2Ev> : !cir.ptr<!u8i>
561
+ ]> : !cir.array<!cir.ptr<!u8i> x 4>
562
+ }> : !rec_anon_struct1
563
+ ```
564
+
565
+ Example 2 (multiple vtables):
566
+ ```mlir
567
+ cir.global linkonce_odr @_ZTV5Child =
568
+ #cir.vtable<{
569
+ #cir.const_array<[
570
+ #cir.ptr<null> : !cir.ptr<!u8i>,
571
+ #cir.global_view<@_ZTI5Child> : !cir.ptr<!u8i>,
572
+ #cir.global_view<@_ZN5Child9MotherFooEv> : !cir.ptr<!u8i>,
573
+ #cir.global_view<@_ZN6Mother10MotherFoo2Ev> : !cir.ptr<!u8i>
574
+ ]> : !cir.array<!cir.ptr<!u8i> x 4>,
575
+ #cir.const_array<[
576
+ #cir.ptr<-8 : i64> : !cir.ptr<!u8i>,
577
+ #cir.global_view<@_ZTI5Child> : !cir.ptr<!u8i>,
578
+ #cir.global_view<@_ZN6Father9FatherFooEv> : !cir.ptr<!u8i>
579
+ ]> : !cir.array<!cir.ptr<!u8i> x 3>
580
+ }> : !rec_anon_struct2
581
+ ```
582
+ }];
583
+
584
+ // `data` is a const record with one element, containing an array of
585
+ // vtable information.
586
+ let parameters = (ins
587
+ AttributeSelfTypeParameter<"">:$type,
588
+ "mlir::ArrayAttr":$data
589
+ );
590
+
591
+ let builders = [
592
+ AttrBuilderWithInferredContext<(ins "mlir::Type":$type,
593
+ "mlir::ArrayAttr":$data), [{
594
+ return $_get(type.getContext(), type, data);
595
+ }]>
596
+ ];
597
+
598
+ let genVerifyDecl = 1;
599
+ let assemblyFormat = [{
600
+ `<` custom<RecordMembers>($data) `>`
601
+ }];
602
+ }
603
+
538
604
//===----------------------------------------------------------------------===//
539
605
// ConstComplexAttr
540
606
//===----------------------------------------------------------------------===//
0 commit comments