[clang] [CIR] Upstream StackSave and StackRestoreOp (PR #136426)
Henrich Lauko via cfe-commits
cfe-commits at lists.llvm.org
Mon Apr 21 01:06:23 PDT 2025
================
@@ -1419,6 +1419,48 @@ def CallOp : CIR_CallOpBase<"call", [NoRegionArguments]> {
}]>];
}
+//===----------------------------------------------------------------------===//
+// StackSave & StackRestoreOp
+//===----------------------------------------------------------------------===//
+
+def StackSaveOp : CIR_Op<"stack_save"> {
+ let summary = "remembers the current state of the function stack";
+ let description = [{
+ Remembers the current state of the function stack. Returns a pointer
+ that later can be passed into cir.stack_restore.
+ Useful for implementing language features like variable length arrays.
+
+ ```mlir
+ %0 = cir.stack_save : <!u8i>
+ ```
+ }];
+
+ let results = (outs CIR_PointerType:$result);
+ let assemblyFormat = "attr-dict `:` qualified(type($result))";
+}
+
+def StackRestoreOp : CIR_Op<"stack_restore"> {
+ let summary = "restores the state of the function stack";
+ let description = [{
+ Restore the state of the function stack to the state it was
+ in when the corresponding cir.stack_save executed.
+ Useful for implementing language features like variable length arrays.
+
+ ```mlir
+ %0 = cir.alloca !cir.ptr<!u8i>, !cir.ptr<!cir.ptr<!u8i>>, ["saved_stack"] {alignment = 8 : i64}
+ %1 = cir.stack_save : <!u8i>
+ cir.store %1, %0 : !cir.ptr<!u8i>, !cir.ptr<!cir.ptr<!u8i>>
+ %2 = cir.load %0 : !cir.ptr<!cir.ptr<!u8i>>, !cir.ptr<!u8i>
+ cir.stack_restore %2 : !cir.ptr<!u8i>
+ ```
+ }];
+
+ let arguments = (ins CIR_PointerType:$ptr);
+ let assemblyFormat = "$ptr attr-dict `:` qualified(type($ptr))";
+
+ let llvmOp = "StackRestoreOp";
----------------
xlauko wrote:
Why is this here, since it is not used? Also it is only in one of these operations.
If used, I would expect not to have explicit `CIRToLLVMStackRestoreOpLowering` and `CIRToLLVMStackSaveOpLowering` patterns, but use the generated one.
https://github.com/llvm/llvm-project/pull/136426
More information about the cfe-commits
mailing list