[llvm] bc8a5d1 - [Patchpoint] Add immarg attributes to patchpoint arguments (#97276)

via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 17 03:00:28 PDT 2024


Author: Csanád Hajdú
Date: 2024-09-17T14:00:24+04:00
New Revision: bc8a5d104c69cee9cb9a870785da1eac62b58e32

URL: https://github.com/llvm/llvm-project/commit/bc8a5d104c69cee9cb9a870785da1eac62b58e32
DIFF: https://github.com/llvm/llvm-project/commit/bc8a5d104c69cee9cb9a870785da1eac62b58e32.diff

LOG: [Patchpoint] Add immarg attributes to patchpoint arguments (#97276)

Added: 
    llvm/test/Transforms/SimplifyCFG/patchpoint-invalid-sink.ll

Modified: 
    llvm/include/llvm/IR/Intrinsics.td
    llvm/test/Verifier/intrinsic-immarg.ll

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/IR/Intrinsics.td b/llvm/include/llvm/IR/Intrinsics.td
index 1bc895eee60f1a..0a74a217a5f010 100644
--- a/llvm/include/llvm/IR/Intrinsics.td
+++ b/llvm/include/llvm/IR/Intrinsics.td
@@ -1632,12 +1632,16 @@ def int_experimental_patchpoint_void : Intrinsic<[],
                                                  [llvm_i64_ty, llvm_i32_ty,
                                                   llvm_ptr_ty, llvm_i32_ty,
                                                   llvm_vararg_ty],
-                                                  [Throws]>;
+                                                  [Throws, ImmArg<ArgIndex<0>>,
+                                                   ImmArg<ArgIndex<1>>,
+                                                   ImmArg<ArgIndex<3>>]>;
 def int_experimental_patchpoint : Intrinsic<[llvm_any_ty],
                                             [llvm_i64_ty, llvm_i32_ty,
                                              llvm_ptr_ty, llvm_i32_ty,
                                              llvm_vararg_ty],
-                                            [Throws]>;
+                                            [Throws, ImmArg<ArgIndex<0>>,
+                                             ImmArg<ArgIndex<1>>,
+                                             ImmArg<ArgIndex<3>>]>;
 
 
 //===------------------------ Garbage Collection Intrinsics ---------------===//

diff  --git a/llvm/test/Transforms/SimplifyCFG/patchpoint-invalid-sink.ll b/llvm/test/Transforms/SimplifyCFG/patchpoint-invalid-sink.ll
new file mode 100644
index 00000000000000..eeb57102340654
--- /dev/null
+++ b/llvm/test/Transforms/SimplifyCFG/patchpoint-invalid-sink.ll
@@ -0,0 +1,35 @@
+; RUN: opt -passes='simplifycfg<sink-common-insts>' -S %s | FileCheck %s
+
+declare void @personalityFn()
+
+define void @test(i1 %c) personality ptr @personalityFn {
+; CHECK-LABEL: define void @test
+; CHECK-LABEL: entry:
+; CHECK-NEXT:    br i1 %c, label %taken, label %untaken
+; CHECK-LABEL: taken:
+; CHECK-NEXT:    invoke void (i64, i32, ptr, i32, ...) @llvm.experimental.patchpoint.void(i64 1, i32 0, ptr null, i32 0)
+; CHECK-LABEL: untaken:
+; CHECK-NEXT:    invoke void (i64, i32, ptr, i32, ...) @llvm.experimental.patchpoint.void(i64 2, i32 0, ptr null, i32 0)
+; CHECK-LABEL: end:
+; CHECK-NEXT:    ret void
+entry:
+  br i1 %c, label %taken, label %untaken
+
+taken:
+  invoke void (i64, i32, ptr, i32, ...) @llvm.experimental.patchpoint.void(i64 1, i32 0, ptr null, i32 0)
+          to label %end unwind label %unwind
+
+untaken:
+  invoke void (i64, i32, ptr, i32, ...) @llvm.experimental.patchpoint.void(i64 2, i32 0, ptr null, i32 0)
+          to label %end unwind label %unwind
+
+end:
+  ret void
+
+unwind:
+  %0 = landingpad { ptr, i32 }
+          cleanup
+  br label %end
+}
+
+declare void @llvm.experimental.patchpoint.void(i64 immarg, i32 immarg, ptr, i32 immarg, ...)

diff  --git a/llvm/test/Verifier/intrinsic-immarg.ll b/llvm/test/Verifier/intrinsic-immarg.ll
index ad70b17e5fb727..e310cd2e0b7819 100644
--- a/llvm/test/Verifier/intrinsic-immarg.ll
+++ b/llvm/test/Verifier/intrinsic-immarg.ll
@@ -238,6 +238,37 @@ define void @calls_statepoint(ptr addrspace(1) %arg0, i64 %arg1, i32 %arg2, i32
   ret void
 }
 
+declare void @llvm.experimental.patchpoint.void(i64, i32, ptr, i32, ...)
+declare i64 @llvm.experimental.patchpoint.i64(i64, i32, ptr, i32, ...)
+
+define void @test_patchpoint(i64 %arg0, i32 %arg1, i32 %arg2) {
+  ; CHECK: immarg operand has non-immediate parameter
+  ; CHECK-NEXT: i64 %arg0
+  ; CHECK-NEXT: call void (i64, i32, ptr, i32, ...) @llvm.experimental.patchpoint.void(i64 %arg0, i32 4, ptr null, i32 0)
+  ; CHECK: immarg operand has non-immediate parameter
+  ; CHECK-NEXT: i32 %arg1
+  ; CHECK-NEXT: call void (i64, i32, ptr, i32, ...) @llvm.experimental.patchpoint.void(i64 0, i32 %arg1, ptr null, i32 0)
+  ; CHECK: immarg operand has non-immediate parameter
+  ; CHECK-NEXT: i32 %arg2
+  ; CHECK-NEXT: call void (i64, i32, ptr, i32, ...) @llvm.experimental.patchpoint.void(i64 0, i32 4, ptr null, i32 %arg2)
+  ; CHECK: immarg operand has non-immediate parameter
+  ; CHECK-NEXT: i64 %arg0
+  ; CHECK-NEXT: %patchpoint0 = call i64 (i64, i32, ptr, i32, ...) @llvm.experimental.patchpoint.i64(i64 %arg0, i32 4, ptr null, i32 0)
+  ; CHECK: immarg operand has non-immediate parameter
+  ; CHECK-NEXT: i32 %arg1
+  ; CHECK-NEXT: %patchpoint1 = call i64 (i64, i32, ptr, i32, ...) @llvm.experimental.patchpoint.i64(i64 0, i32 %arg1, ptr null, i32 0)
+  ; CHECK: immarg operand has non-immediate parameter
+  ; CHECK-NEXT: i32 %arg2
+  ; CHECK-NEXT: %patchpoint2 = call i64 (i64, i32, ptr, i32, ...) @llvm.experimental.patchpoint.i64(i64 0, i32 4, ptr null, i32 %arg2)
+  call void (i64, i32, ptr, i32, ...) @llvm.experimental.patchpoint.void(i64 %arg0, i32 4, ptr null, i32 0)
+  call void (i64, i32, ptr, i32, ...) @llvm.experimental.patchpoint.void(i64 0, i32 %arg1, ptr null, i32 0)
+  call void (i64, i32, ptr, i32, ...) @llvm.experimental.patchpoint.void(i64 0, i32 4, ptr null, i32 %arg2)
+  %patchpoint0 = call i64 (i64, i32, ptr, i32, ...) @llvm.experimental.patchpoint.i64(i64 %arg0, i32 4, ptr null, i32 0)
+  %patchpoint1 = call i64 (i64, i32, ptr, i32, ...) @llvm.experimental.patchpoint.i64(i64 0, i32 %arg1, ptr null, i32 0)
+  %patchpoint2 = call i64 (i64, i32, ptr, i32, ...) @llvm.experimental.patchpoint.i64(i64 0, i32 4, ptr null, i32 %arg2)
+  ret void
+}
+
 declare void @llvm.hwasan.check.memaccess(ptr, ptr, i32)
 
 define void @hwasan_check_memaccess(ptr %arg0,ptr %arg1, i32 %arg2) {


        


More information about the llvm-commits mailing list