@@ -3559,6 +3559,63 @@ def CIR_ArrayDtor : CIR_ArrayInitDestroy<"array.dtor"> {
35593559 }];
35603560}
35613561
3562+ //===----------------------------------------------------------------------===//
3563+ // GetRuntimeMemberOp
3564+ //===----------------------------------------------------------------------===//
3565+
3566+ def CIR_GetRuntimeMemberOp : CIR_Op<"get_runtime_member"> {
3567+ let summary = "Get the address of a member of a record";
3568+ let description = [{
3569+ The `cir.get_runtime_member` operation gets the address of a member from
3570+ the input record. The target member is given by a value of type
3571+ `!cir.data_member` (i.e. a pointer-to-data-member value).
3572+
3573+ This operation differs from `cir.get_member` in when the target member can
3574+ be determined. For the `cir.get_member` operation, the target member is
3575+ specified as a constant index so the member it returns access to is known
3576+ when the operation is constructed. For the `cir.get_runtime_member`
3577+ operation, the target member is given through a pointer-to-data-member
3578+ value which is unknown until the program being compiled is executed. In
3579+ other words, `cir.get_member` represents a normal member access through the
3580+ `.` operator in C/C++:
3581+
3582+ ```cpp
3583+ struct Foo { int x; };
3584+ Foo f;
3585+ (void)f.x; // cir.get_member
3586+ ```
3587+
3588+ And `cir.get_runtime_member` represents a member access through the `.*` or
3589+ the `->*` operator in C++:
3590+
3591+ ```cpp
3592+ struct Foo { int x; }
3593+ Foo f;
3594+ Foo *p;
3595+ int Foo::*member;
3596+
3597+ (void)f.*member; // cir.get_runtime_member
3598+ (void)p->*member; // cir.get_runtime_member
3599+ ```
3600+
3601+ This operation expects a pointer to the base record as well as the pointer
3602+ to the target member.
3603+ }];
3604+
3605+ let arguments = (ins
3606+ Arg<CIR_PtrToRecordType, "address of the record object", [MemRead]>:$addr,
3607+ Arg<CIR_DataMemberType, "pointer to the target member">:$member);
3608+
3609+ let results = (outs Res<CIR_PointerType, "">:$result);
3610+
3611+ let assemblyFormat = [{
3612+ $addr `[` $member `:` qualified(type($member)) `]` attr-dict
3613+ `:` qualified(type($addr)) `->` qualified(type($result))
3614+ }];
3615+
3616+ let hasVerifier = 1;
3617+ }
3618+
35623619//===----------------------------------------------------------------------===//
35633620// VecCreate
35643621//===----------------------------------------------------------------------===//
0 commit comments