================
@@ -496,6 +496,46 @@ def CIR_GlobalViewAttr : CIR_Attr<"GlobalView", 
"global_view", [
   }];
 }
 
+//===----------------------------------------------------------------------===//
+// VTableAttr
+//===----------------------------------------------------------------------===//
+
+def VTableAttr : CIR_Attr<"VTable", "vtable", [TypedAttrInterface]> {
+  let summary = "Represents a C++ vtable";
+  let description = [{
+    Wraps a #cir.const_record containing vtable data.
----------------
andykaylor wrote:

This can potentially wrap a record containing multiple vtable arrays. In the 
simple case, we create an anonymous record that has a single array element, 
which looks like this:

```
cir.global linkonce_odr @_ZTV6Mother =
  #cir.vtable<{
    #cir.const_array<[
      #cir.ptr<null> : !cir.ptr<!u8i>,
      #cir.global_view<@_ZTI6Mother> : !cir.ptr<!u8i>,
      #cir.global_view<@_ZN6Mother9MotherFooEv> : !cir.ptr<!u8i>,
      #cir.global_view<@_ZN6Mother10MotherFoo2Ev> : !cir.ptr<!u8i>
    ]> : !cir.array<!cir.ptr<!u8i> x 4>
  }> : !rec_anon_struct2 {alignment = 8 : i64 }
```
But in cases involving multiple inheritence, there can be multiple vtables 
within the record, like this:

```
cir.global linkonce_odr @_ZTV5Child =
  #cir.vtable<{
    #cir.const_array<[
      #cir.ptr<null> : !cir.ptr<!u8i>,
      #cir.global_view<@_ZTI5Child> : !cir.ptr<!u8i>,
      #cir.global_view<@_ZN5Child9MotherFooEv> : !cir.ptr<!u8i>,
      #cir.global_view<@_ZN6Mother10MotherFoo2Ev> : !cir.ptr<!u8i>
    ]> : !cir.array<!cir.ptr<!u8i> x 4>,
    #cir.const_array<[
      #cir.ptr<-8 : i64> : !cir.ptr<!u8i>,
      #cir.global_view<@_ZTI5Child> : !cir.ptr<!u8i>,
      #cir.global_view<@_ZN6Father9FatherFooEv> : !cir.ptr<!u8i>
    ]> : !cir.array<!cir.ptr<!u8i> x 3>
  }> : !rec_anon_struct4 {alignment = 8 : i64}
```
The `index` attribute in the `address_point` selects which of the wrapped 
vtables is being referenced:

`    %6 = cir.vtable.address_point(@_ZTV5Child, address_point = <index = 1, 
offset = 2>) : !cir.vptr

https://github.com/llvm/llvm-project/pull/154415
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to