@@ -4227,13 +4227,21 @@ def MemChrOp : CIR_Op<"libc.memchr"> {
42274227}
42284228
42294229//===----------------------------------------------------------------------===//
4230- // ReturnAddrOp
4230+ // ReturnAddrOp and FrameAddrOp
42314231//===----------------------------------------------------------------------===//
42324232
4233- def ReturnAddrOp : CIR_Op<"return_address" > {
4233+ class FuncAddrBuiltinOp<string mnemonic> : CIR_Op<mnemonic, [] > {
42344234 let arguments = (ins UInt32:$level);
4235- let summary = "The return address of the current function, or of one of its callers";
42364235 let results = (outs Res<VoidPtr, "">:$result);
4236+ let assemblyFormat = [{
4237+ `(` $level `)` attr-dict
4238+ }];
4239+ let hasVerifier = 0;
4240+ }
4241+
4242+ def ReturnAddrOp : FuncAddrBuiltinOp<"return_address"> {
4243+ let summary =
4244+ "The return address of the current function, or of one of its callers";
42374245
42384246 let description = [{
42394247 Represents call to builtin function ` __builtin_return_address` in CIR.
@@ -4250,11 +4258,34 @@ def ReturnAddrOp : CIR_Op<"return_address"> {
42504258 %p = return_address(%level) -> !cir.ptr<!void>
42514259 ```
42524260 }];
4261+ }
42534262
4254- let assemblyFormat = [{
4255- `(` $level `)` attr-dict
4263+ def FrameAddrOp : FuncAddrBuiltinOp<"frame_address"> {
4264+ let summary =
4265+ "The frame address of the current function, or of one of its callers";
4266+
4267+ let description = [{
4268+ Represents call to builtin function ` __builtin_frame_address` in CIR.
4269+ This builtin function returns the frame address of the current function,
4270+ or of one of its callers. The frame is the area on the stack that holds
4271+ local variables and saved registers. The frame address is normally the
4272+ address of the first word pushed on to the stack by the function.
4273+ However, the exact definition depends upon the processor and the calling
4274+ convention. If the processor has a dedicated frame pointer register, and
4275+ the function has a frame, then __builtin_frame_address returns the value of
4276+ the frame pointer register.
4277+
4278+ The `level` argument is number of frames to scan up the call stack.
4279+ For instance, value of 0 yields the frame address of the current function,
4280+ value of 1 yields the frame address of the caller of the current function,
4281+ and so forth.
4282+
4283+ Examples:
4284+
4285+ ```mlir
4286+ %p = frame_address(%level) -> !cir.ptr<!void>
4287+ ```
42564288 }];
4257- let hasVerifier = 0;
42584289}
42594290
42604291//===----------------------------------------------------------------------===//
0 commit comments