@@ -4218,13 +4218,21 @@ def MemChrOp : CIR_Op<"libc.memchr"> {
42184218}
42194219
42204220//===----------------------------------------------------------------------===//
4221- // ReturnAddrOp
4221+ // ReturnAddrOp and FrameAddrOp
42224222//===----------------------------------------------------------------------===//
42234223
4224- def ReturnAddrOp : CIR_Op<"return_address" > {
4224+ class FuncAddrBuiltinOp<string mnemonic> : CIR_Op<mnemonic, [] > {
42254225 let arguments = (ins UInt32:$level);
4226- let summary = "The return address of the current function, or of one of its callers";
42274226 let results = (outs Res<VoidPtr, "">:$result);
4227+ let assemblyFormat = [{
4228+ `(` $level `)` attr-dict
4229+ }];
4230+ let hasVerifier = 0;
4231+ }
4232+
4233+ def ReturnAddrOp : FuncAddrBuiltinOp<"return_address"> {
4234+ let summary =
4235+ "The return address of the current function, or of one of its callers";
42284236
42294237 let description = [{
42304238 Represents call to builtin function ` __builtin_return_address` in CIR.
@@ -4241,11 +4249,34 @@ def ReturnAddrOp : CIR_Op<"return_address"> {
42414249 %p = return_address(%level) -> !cir.ptr<!void>
42424250 ```
42434251 }];
4252+ }
42444253
4245- let assemblyFormat = [{
4246- `(` $level `)` attr-dict
4254+ def FrameAddrOp : FuncAddrBuiltinOp<"frame_address"> {
4255+ let summary =
4256+ "The frame address of the current function, or of one of its callers";
4257+
4258+ let description = [{
4259+ Represents call to builtin function ` __builtin_frame_address` in CIR.
4260+ This builtin function returns the frame address of the current function,
4261+ or of one of its callers. The frame is the area on the stack that holds
4262+ local variables and saved registers. The frame address is normally the
4263+ address of the first word pushed on to the stack by the function.
4264+ However, the exact definition depends upon the processor and the calling
4265+ convention. If the processor has a dedicated frame pointer register, and
4266+ the function has a frame, then __builtin_frame_address returns the value of
4267+ the frame pointer register.
4268+
4269+ The `level` argument is number of frames to scan up the call stack.
4270+ For instance, value of 0 yields the frame address of the current function,
4271+ value of 1 yields the frame address of the caller of the current function,
4272+ and so forth.
4273+
4274+ Examples:
4275+
4276+ ```mlir
4277+ %p = frame_address(%level) -> !cir.ptr<!void>
4278+ ```
42474279 }];
4248- let hasVerifier = 0;
42494280}
42504281
42514282//===----------------------------------------------------------------------===//
0 commit comments