[Mlir-commits] [mlir] b8064c1 - [mlir][llvm] Add trap intrinsics to the dialect
Victor Perez
llvmlistbot at llvm.org
Tue May 2 02:09:40 PDT 2023
Author: Victor Perez
Date: 2023-05-02T10:09:31+01:00
New Revision: b8064c1a039ef819a2f2ce0ca79990666b23366f
URL: https://github.com/llvm/llvm-project/commit/b8064c1a039ef819a2f2ce0ca79990666b23366f
DIFF: https://github.com/llvm/llvm-project/commit/b8064c1a039ef819a2f2ce0ca79990666b23366f.diff
LOG: [mlir][llvm] Add trap intrinsics to the dialect
Define llvm.trap, llvm.debugtrap, and llvm.ubsantrap intrinsics in the
llvm dialect.
Signed-off-by: Victor Perez <victor.perez at codeplay.com>
Differential Revision: https://reviews.llvm.org/D149574
Added:
Modified:
mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td
mlir/test/Target/LLVMIR/Import/intrinsic.ll
mlir/test/Target/LLVMIR/llvmir-intrinsics.mlir
Removed:
################################################################################
diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td
index 4b30d0c164c81..e8e1712cc4f3a 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td
@@ -716,6 +716,26 @@ def LLVM_masked_compressstore
let arguments = (ins LLVM_AnyVector, LLVM_AnyPointer, LLVM_VectorOf<I1>);
}
+//
+// Trap intrinsics.
+//
+
+def LLVM_Trap : LLVM_ZeroResultIntrOp<"trap">;
+
+def LLVM_DebugTrap : LLVM_ZeroResultIntrOp<"debugtrap">;
+
+def LLVM_UBSanTrap : LLVM_ZeroResultIntrOp<"ubsantrap"> {
+ let arguments = (ins I8Attr:$failureKind);
+ string llvmBuilder = [{
+ builder.CreateIntrinsic(
+ llvm::Intrinsic::ubsantrap, {}, {builder.getInt8($failureKind)});
+ }];
+ string mlirBuilder = [{
+ $_op =
+ $_builder.create<LLVM::UBSanTrap>($_location, $_int_attr($failureKind));
+ }];
+}
+
/// Create a call to vscale intrinsic.
def LLVM_vscale : LLVM_IntrOp<"vscale", [0], [], [], 1>;
diff --git a/mlir/test/Target/LLVMIR/Import/intrinsic.ll b/mlir/test/Target/LLVMIR/Import/intrinsic.ll
index 7fc1f39148e79..3c22a603da574 100644
--- a/mlir/test/Target/LLVMIR/Import/intrinsic.ll
+++ b/mlir/test/Target/LLVMIR/Import/intrinsic.ll
@@ -355,6 +355,17 @@ define void @masked_expand_compress_intrinsics(ptr %0, <7 x i1> %1, <7 x float>
ret void
}
+; CHECK-LABEL: llvm.func @trap_intrinsics
+define void @trap_intrinsics() {
+ ; CHECK: "llvm.intr.trap"() : () -> ()
+ call void @llvm.trap()
+ ; CHECK: "llvm.intr.debugtrap"() : () -> ()
+ call void @llvm.debugtrap()
+ ; CHECK: "llvm.intr.ubsantrap"() {failureKind = 1 : i8} : () -> ()
+ call void @llvm.ubsantrap(i8 1)
+ ret void
+}
+
; CHECK-LABEL: llvm.func @memcpy_test
define void @memcpy_test(i32 %0, ptr %1, ptr %2) {
; CHECK: %[[FALSE:.+]] = llvm.mlir.constant(false) : i1
@@ -743,6 +754,9 @@ declare <7 x float> @llvm.masked.gather.v7f32.v7p0(<7 x ptr>, i32 immarg, <7 x i
declare void @llvm.masked.scatter.v7f32.v7p0(<7 x float>, <7 x ptr>, i32 immarg, <7 x i1>)
declare <7 x float> @llvm.masked.expandload.v7f32(ptr, <7 x i1>, <7 x float>)
declare void @llvm.masked.compressstore.v7f32(<7 x float>, ptr, <7 x i1>)
+declare void @llvm.trap()
+declare void @llvm.debugtrap()
+declare void @llvm.ubsantrap(i8 immarg)
declare void @llvm.memcpy.p0.p0.i32(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i32, i1 immarg)
declare void @llvm.memcpy.inline.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64 immarg, i1 immarg)
declare void @llvm.memmove.p0.p0.i32(ptr nocapture writeonly, ptr nocapture readonly, i32, i1 immarg)
diff --git a/mlir/test/Target/LLVMIR/llvmir-intrinsics.mlir b/mlir/test/Target/LLVMIR/llvmir-intrinsics.mlir
index 7f3c26ab33b82..80a52224a8397 100644
--- a/mlir/test/Target/LLVMIR/llvmir-intrinsics.mlir
+++ b/mlir/test/Target/LLVMIR/llvmir-intrinsics.mlir
@@ -374,6 +374,17 @@ llvm.func @masked_expand_compress_intrinsics(%ptr: !llvm.ptr<f32>, %mask: vector
llvm.return
}
+// CHECK-LABEL: @trap_intrinsics
+llvm.func @trap_intrinsics() {
+ // CHECK: call void @llvm.trap()
+ "llvm.intr.trap"() : () -> ()
+ // CHECK: call void @llvm.debugtrap()
+ "llvm.intr.debugtrap"() : () -> ()
+ // CHECK: call void @llvm.ubsantrap(i8 1)
+ "llvm.intr.ubsantrap"() {failureKind = 1 : i8} : () -> ()
+ llvm.return
+}
+
// CHECK-LABEL: @memcpy_test
llvm.func @memcpy_test(%arg0: i32, %arg2: !llvm.ptr<i8>, %arg3: !llvm.ptr<i8>) {
%i1 = llvm.mlir.constant(false) : i1
@@ -788,6 +799,9 @@ llvm.func @lifetime(%p: !llvm.ptr) {
// CHECK-DAG: declare void @llvm.masked.scatter.v7f32.v7p0(<7 x float>, <7 x ptr>, i32 immarg, <7 x i1>)
// CHECK-DAG: declare <7 x float> @llvm.masked.expandload.v7f32(ptr nocapture, <7 x i1>, <7 x float>)
// CHECK-DAG: declare void @llvm.masked.compressstore.v7f32(<7 x float>, ptr nocapture, <7 x i1>)
+// CHECK-DAG: declare void @llvm.trap()
+// CHECK-DAG: declare void @llvm.debugtrap()
+// CHECK-DAG: declare void @llvm.ubsantrap(i8 immarg)
// CHECK-DAG: declare void @llvm.memcpy.p0.p0.i32(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i32, i1 immarg)
// CHECK-DAG: declare void @llvm.memcpy.inline.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64 immarg, i1 immarg)
// CHECK-DAG: declare { i32, i1 } @llvm.sadd.with.overflow.i32(i32, i32)
More information about the Mlir-commits
mailing list