@@ -2605,31 +2605,25 @@ def CIR_VTableAddrPointOp : CIR_Op<"vtable.address_point", [
2605
2605
}];
2606
2606
2607
2607
let arguments = (ins
2608
- OptionalAttr<FlatSymbolRefAttr>:$name,
2609
- Optional<CIR_AnyType>:$sym_addr,
2608
+ FlatSymbolRefAttr:$name,
2610
2609
CIR_AddressPointAttr:$address_point
2611
2610
);
2612
2611
2613
2612
let results = (outs Res<CIR_PtrToVPtr, "", []>:$addr);
2614
2613
2615
2614
let assemblyFormat = [{
2616
2615
`(`
2617
- ($name^)?
2618
- ($sym_addr^ `:` type($sym_addr))?
2619
- `,`
2620
- `address_point` `=` $address_point
2616
+ $name `,` `address_point` `=` $address_point
2621
2617
`)`
2622
2618
`:` qualified(type($addr)) attr-dict
2623
2619
}];
2624
-
2625
- let hasVerifier = 1;
2626
2620
}
2627
2621
2628
2622
//===----------------------------------------------------------------------===//
2629
- // VTableGetVptr
2623
+ // VTableGetVPtr
2630
2624
//===----------------------------------------------------------------------===//
2631
2625
2632
- def CIR_VTableGetVptrOp : CIR_Op<"vtable.get_vptr", [Pure]> {
2626
+ def CIR_VTableGetVPtrOp : CIR_Op<"vtable.get_vptr", [Pure]> {
2633
2627
let summary = "Get a the address of the vtable pointer for an object";
2634
2628
let description = [{
2635
2629
The `vtable.get_vptr` operation retrieves the address of the vptr for a
@@ -2648,13 +2642,13 @@ def CIR_VTableGetVptrOp : CIR_Op<"vtable.get_vptr", [Pure]> {
2648
2642
}];
2649
2643
2650
2644
let arguments = (ins
2651
- Arg<CIR_PointerType, "the vptr address", [MemRead]>:$src);
2652
-
2653
- let results = (outs CIR_PtrToVPtr:$vptr_ty);
2645
+ Arg<CIR_PointerType, "the vptr address", [MemRead]>:$src
2646
+ );
2654
2647
2648
+ let results = (outs CIR_PtrToVPtr:$result);
2655
2649
2656
2650
let assemblyFormat = [{
2657
- $src `:` qualified(type($src)) `->` qualified(type($vptr_ty )) attr-dict
2651
+ $src `:` qualified(type($src)) `->` qualified(type($result )) attr-dict
2658
2652
}];
2659
2653
2660
2654
}
@@ -2674,14 +2668,18 @@ def CIR_VTableGetVirtualFnAddrOp : CIR_Op<"vtable.get_virtual_fn_addr", [
2674
2668
the address of the virtual function pointer, which can then be loaded and
2675
2669
called.
2676
2670
2671
+ The `vptr` operand must be a `!cir.ptr<!cir.vptr>` value, which would
2672
+ have been returned by a previous call to `cir.vatble.get_vptr`. The
2673
+ `index` operand is an index of the virtual function in the vtable.
2674
+
2677
2675
The return type is a pointer-to-pointer to the function type.
2678
2676
2679
2677
Example:
2680
2678
```mlir
2681
2679
%2 = cir.load %0 : !cir.ptr<!cir.ptr<!rec_C>>, !cir.ptr<!rec_C>
2682
2680
%3 = cir.vtable.get_vptr %2 : !cir.ptr<!rec_C> -> !cir.ptr<!cir.vptr>
2683
2681
%4 = cir.load %3 : !cir.ptr<!cir.vptr>, !cir.vptr
2684
- %5 = cir.vtable.get_virtual_fn_addr(%4, index = 2) : !cir.vptr
2682
+ %5 = cir.vtable.get_virtual_fn_addr %4[2] : !cir.vptr
2685
2683
-> !cir.ptr<!cir.ptr<!cir.func<(!cir.ptr<!rec_C>) -> !s32i>>>
2686
2684
%6 = cir.load align(8) %5 : !cir.ptr<!cir.ptr<!cir.func<(!cir.ptr<!rec_C>)
2687
2685
-> !s32i>>>,
@@ -2693,30 +2691,13 @@ def CIR_VTableGetVirtualFnAddrOp : CIR_Op<"vtable.get_virtual_fn_addr", [
2693
2691
2694
2692
let arguments = (ins
2695
2693
Arg<CIR_VPtrType, "vptr", [MemRead]>:$vptr,
2696
- IndexAttr:$index_attr );
2694
+ I64Attr:$index );
2697
2695
2698
- let results = (outs CIR_PointerType:$vfptr_ty );
2696
+ let results = (outs CIR_PointerType:$result );
2699
2697
2700
2698
let assemblyFormat = [{
2701
- `(`
2702
- $vptr `,` `index` `=` $index_attr
2703
- `)`
2704
- `:` qualified(type($vptr)) `,` qualified(type($vfptr_ty)) attr-dict
2705
- }];
2706
-
2707
- let builders = [
2708
- OpBuilder<(ins "mlir::Type":$type,
2709
- "mlir::Value":$value,
2710
- "unsigned":$index),
2711
- [{
2712
- mlir::APInt fnIdx(64, index);
2713
- build($_builder, $_state, type, value, fnIdx);
2714
- }]>
2715
- ];
2716
-
2717
- let extraClassDeclaration = [{
2718
- /// Return the index of the record member being accessed.
2719
- uint64_t getIndex() { return getIndexAttr().getZExtValue(); }
2699
+ $vptr `[` $index `]` attr-dict
2700
+ `:` qualified(type($vptr)) `->` qualified(type($result))
2720
2701
}];
2721
2702
}
2722
2703
0 commit comments