From fa581f943887c1d1fd95b01ae5f28140e97331bf Mon Sep 17 00:00:00 2001 From: Denys Shabalin Date: Tue, 9 Feb 2021 15:09:02 +0100 Subject: [PATCH] [mlir] Add stacksave, stackrestore to llvm dialect Reviewed By: ftynse Differential Revision: https://reviews.llvm.org/D96333 --- mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td | 13 +++++++++++++ mlir/test/Target/llvmir-intrinsics.mlir | 14 ++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td index e44dbb8f17ec..368373519ff4 100644 --- a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td +++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td @@ -1277,6 +1277,19 @@ def LLVM_CoroResumeOp : LLVM_IntrOp<"coro.resume", [], [], [], 0> { let assemblyFormat = "$handle attr-dict"; } +// +// Stack save/restore intrinsics. +// + +def LLVM_StackSaveOp : LLVM_OneResultIntrOp<"stacksave"> { + let assemblyFormat = "attr-dict `:` type($res)"; +} + +def LLVM_StackRestoreOp : LLVM_ZeroResultIntrOp<"stackrestore"> { + let arguments = (ins LLVM_i8Ptr:$ptr); + let assemblyFormat = "$ptr attr-dict"; +} + // // Vector Reductions. // diff --git a/mlir/test/Target/llvmir-intrinsics.mlir b/mlir/test/Target/llvmir-intrinsics.mlir index 12b470a8176b..a9fe6f692c68 100644 --- a/mlir/test/Target/llvmir-intrinsics.mlir +++ b/mlir/test/Target/llvmir-intrinsics.mlir @@ -405,6 +405,20 @@ llvm.func @coro_resume(%arg0: !llvm.ptr) { llvm.return } +// CHECK-LABEL: @stack_save +llvm.func @stack_save() { + // CHECK: call i8* @llvm.stacksave + %0 = llvm.intr.stacksave : !llvm.ptr + llvm.return +} + +// CHECK-LABEL: @stack_restore +llvm.func @stack_restore(%arg0: !llvm.ptr) { + // CHECK: call void @llvm.stackrestore + llvm.intr.stackrestore %arg0 + llvm.return +} + // Check that intrinsics are declared with appropriate types. // CHECK-DAG: declare float @llvm.fma.f32(float, float, float) // CHECK-DAG: declare <8 x float> @llvm.fma.v8f32(<8 x float>, <8 x float>, <8 x float>) #0