@@ -511,18 +511,21 @@ def CIR_MethodAttr : CIR_Attr<"Method", "method", [TypedAttrInterface]> {
511511 If the member function is a non-virtual function, the `symbol` parameter
512512 gives the global symbol for the non-virtual member function.
513513
514- Virtual function handling is not yet implemented.
514+ If the member function is a virtual function, the `vtable_offset` parameter
515+ gives the offset of the vtable entry corresponding to the virtual member
516+ function.
515517
516- If `symbol` is not present, the attribute represents a null pointer
517- constant.
518+ `symbol` and `vtable_offset` cannot be present at the same time. If both of
519+ `symbol` and `vtable_offset` are not present, the attribute represents a
520+ null pointer constant.
518521
519522 Examples:
520523 ```
521524 // Non-virtual method
522525 %0 = cir.const #cir.method<@_ZN1S2m1Ei> :
523526 !cir.method<!cir.func<(!s32i)> in !rec_S>
524527
525- // Virtual method (not yet implemented)
528+ // Virtual method
526529 %1 = cir.const #cir.method<vtable_offset = 8> :
527530 !cir.method<!cir.func<(!s32i)> in !rec_S>
528531
@@ -534,23 +537,35 @@ def CIR_MethodAttr : CIR_Attr<"Method", "method", [TypedAttrInterface]> {
534537 let parameters = (ins AttributeSelfTypeParameter<
535538 "", "cir::MethodType">:$type,
536539 OptionalParameter<
537- "std::optional<mlir::FlatSymbolRefAttr>">:$symbol);
540+ "std::optional<mlir::FlatSymbolRefAttr>">:$symbol,
541+ OptionalParameter<
542+ "std::optional<uint64_t>">:$vtable_offset);
538543
539544 let builders = [
540545 AttrBuilderWithInferredContext<(ins "cir::MethodType":$type), [{
541- return $_get(type.getContext(), type, std::nullopt);
546+ return $_get(type.getContext(), type, std::nullopt, std::nullopt );
542547 }]>,
543548 AttrBuilderWithInferredContext<(ins "cir::MethodType":$type,
544549 "mlir::FlatSymbolRefAttr":$symbol), [{
545- return $_get(type.getContext(), type, symbol);
550+ return $_get(type.getContext(), type, symbol, std::nullopt);
551+ }]>,
552+ AttrBuilderWithInferredContext<(ins "cir::MethodType":$type,
553+ "uint64_t":$vtable_offset), [{
554+ return $_get(type.getContext(), type, std::nullopt, vtable_offset);
546555 }]>,
547556 ];
548557
549558 let hasCustomAssemblyFormat = 1;
550559
560+ let genVerifyDecl = 1;
561+
551562 let extraClassDeclaration = [{
552563 bool isNull() const {
553- return !getSymbol().has_value();
564+ return !getSymbol().has_value() && !getVtableOffset().has_value();
565+ }
566+
567+ bool isVirtual() const {
568+ return getVtableOffset().has_value();
554569 }
555570 }];
556571}
0 commit comments