@@ -1749,6 +1749,39 @@ def CIR_VTableAddrPointOp : CIR_Op<"vtable.address_point", [
17491749 }];
17501750}
17511751
1752+ //===----------------------------------------------------------------------===//
1753+ // VTableGetVPtr
1754+ //===----------------------------------------------------------------------===//
1755+
1756+ def CIR_VTableGetVPtrOp : CIR_Op<"vtable.get_vptr", [Pure]> {
1757+ let summary = "Get a the address of the vtable pointer for an object";
1758+ let description = [{
1759+ The `vtable.get_vptr` operation retrieves the address of the vptr for a
1760+ C++ object. This operation requires that the object pointer points to
1761+ the start of a complete object. (TODO: Describe how we get that).
1762+ The vptr will always be at offset zero in the object, but this operation
1763+ is more explicit about what is being retrieved than a direct bitcast.
1764+
1765+ The return type is always `!cir.ptr<!cir.vptr>`.
1766+
1767+ Example:
1768+ ```mlir
1769+ %2 = cir.load %0 : !cir.ptr<!cir.ptr<!rec_C>>, !cir.ptr<!rec_C>
1770+ %3 = cir.vtable.get_vptr %2 : !cir.ptr<!rec_C> -> !cir.ptr<!cir.vptr>
1771+ ```
1772+ }];
1773+
1774+ let arguments = (ins
1775+ Arg<CIR_PointerType, "the vptr address", [MemRead]>:$src
1776+ );
1777+
1778+ let results = (outs CIR_PtrToVPtr:$result);
1779+
1780+ let assemblyFormat = [{
1781+ $src `:` qualified(type($src)) `->` qualified(type($result)) attr-dict
1782+ }];
1783+ }
1784+
17521785//===----------------------------------------------------------------------===//
17531786// SetBitfieldOp
17541787//===----------------------------------------------------------------------===//
@@ -2210,6 +2243,68 @@ def CIR_CallOp : CIR_CallOpBase<"call", [NoRegionArguments]> {
22102243 ];
22112244}
22122245
2246+ //===----------------------------------------------------------------------===//
2247+ // ReturnAddrOp and FrameAddrOp
2248+ //===----------------------------------------------------------------------===//
2249+
2250+ class CIR_FuncAddrBuiltinOp<string mnemonic> : CIR_Op<mnemonic, []> {
2251+ let arguments = (ins CIR_UInt32:$level);
2252+ let results = (outs CIR_VoidPtrType:$result);
2253+ let assemblyFormat = [{
2254+ `(` $level `)` attr-dict
2255+ }];
2256+ }
2257+
2258+ def CIR_ReturnAddrOp : CIR_FuncAddrBuiltinOp<"return_address"> {
2259+ let summary =
2260+ "The return address of the current function, or of one of its callers";
2261+
2262+ let description = [{
2263+ Represents a call to builtin function ` __builtin_return_address` in CIR.
2264+ This builtin function returns the return address of the current function,
2265+ or of one of its callers.
2266+
2267+ The `level` argument is number of frames to scan up the call stack.
2268+ For instance, value of 0 yields the return address of the current function,
2269+ value of 1 yields the return address of the caller of the current function,
2270+ and so forth.
2271+
2272+ Examples:
2273+
2274+ ```mlir
2275+ %p = return_address(%level) -> !cir.ptr<!void>
2276+ ```
2277+ }];
2278+ }
2279+
2280+ def CIR_FrameAddrOp : CIR_FuncAddrBuiltinOp<"frame_address"> {
2281+ let summary =
2282+ "The frame address of the current function, or of one of its callers";
2283+
2284+ let description = [{
2285+ Represents a call to builtin function ` __builtin_frame_address` in CIR.
2286+ This builtin function returns the frame address of the current function,
2287+ or of one of its callers. The frame is the area on the stack that holds
2288+ local variables and saved registers. The frame address is normally the
2289+ address of the first word pushed on to the stack by the function.
2290+ However, the exact definition depends upon the processor and the calling
2291+ convention. If the processor has a dedicated frame pointer register, and
2292+ the function has a frame, then __builtin_frame_address returns the value of
2293+ the frame pointer register.
2294+
2295+ The `level` argument is number of frames to scan up the call stack.
2296+ For instance, value of 0 yields the frame address of the current function,
2297+ value of 1 yields the frame address of the caller of the current function,
2298+ and so forth.
2299+
2300+ Examples:
2301+
2302+ ```mlir
2303+ %p = frame_address(%level) -> !cir.ptr<!void>
2304+ ```
2305+ }];
2306+ }
2307+
22132308//===----------------------------------------------------------------------===//
22142309// StackSaveOp & StackRestoreOp
22152310//===----------------------------------------------------------------------===//
0 commit comments