@@ -2605,31 +2605,25 @@ def CIR_VTableAddrPointOp : CIR_Op<"vtable.address_point", [
26052605 }];
26062606
26072607 let arguments = (ins
2608- OptionalAttr<FlatSymbolRefAttr>:$name,
2609- Optional<CIR_AnyType>:$sym_addr,
2608+ FlatSymbolRefAttr:$name,
26102609 CIR_AddressPointAttr:$address_point
26112610 );
26122611
26132612 let results = (outs Res<CIR_PtrToVPtr, "", []>:$addr);
26142613
26152614 let assemblyFormat = [{
26162615 `(`
2617- ($name^)?
2618- ($sym_addr^ `:` type($sym_addr))?
2619- `,`
2620- `address_point` `=` $address_point
2616+ $name `,` `address_point` `=` $address_point
26212617 `)`
26222618 `:` qualified(type($addr)) attr-dict
26232619 }];
2624-
2625- let hasVerifier = 1;
26262620}
26272621
26282622//===----------------------------------------------------------------------===//
2629- // VTableGetVptr
2623+ // VTableGetVPtr
26302624//===----------------------------------------------------------------------===//
26312625
2632- def CIR_VTableGetVptrOp : CIR_Op<"vtable.get_vptr", [Pure]> {
2626+ def CIR_VTableGetVPtrOp : CIR_Op<"vtable.get_vptr", [Pure]> {
26332627 let summary = "Get a the address of the vtable pointer for an object";
26342628 let description = [{
26352629 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]> {
26482642 }];
26492643
26502644 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+ );
26542647
2648+ let results = (outs CIR_PtrToVPtr:$result);
26552649
26562650 let assemblyFormat = [{
2657- $src `:` qualified(type($src)) `->` qualified(type($vptr_ty )) attr-dict
2651+ $src `:` qualified(type($src)) `->` qualified(type($result )) attr-dict
26582652 }];
26592653
26602654}
@@ -2674,14 +2668,18 @@ def CIR_VTableGetVirtualFnAddrOp : CIR_Op<"vtable.get_virtual_fn_addr", [
26742668 the address of the virtual function pointer, which can then be loaded and
26752669 called.
26762670
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+
26772675 The return type is a pointer-to-pointer to the function type.
26782676
26792677 Example:
26802678 ```mlir
26812679 %2 = cir.load %0 : !cir.ptr<!cir.ptr<!rec_C>>, !cir.ptr<!rec_C>
26822680 %3 = cir.vtable.get_vptr %2 : !cir.ptr<!rec_C> -> !cir.ptr<!cir.vptr>
26832681 %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
26852683 -> !cir.ptr<!cir.ptr<!cir.func<(!cir.ptr<!rec_C>) -> !s32i>>>
26862684 %6 = cir.load align(8) %5 : !cir.ptr<!cir.ptr<!cir.func<(!cir.ptr<!rec_C>)
26872685 -> !s32i>>>,
@@ -2693,30 +2691,13 @@ def CIR_VTableGetVirtualFnAddrOp : CIR_Op<"vtable.get_virtual_fn_addr", [
26932691
26942692 let arguments = (ins
26952693 Arg<CIR_VPtrType, "vptr", [MemRead]>:$vptr,
2696- IndexAttr:$index_attr );
2694+ I64Attr:$index );
26972695
2698- let results = (outs CIR_PointerType:$vfptr_ty );
2696+ let results = (outs CIR_PointerType:$result );
26992697
27002698 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))
27202701 }];
27212702}
27222703
0 commit comments