Skip to content

Commit

Permalink
[Patchpoint] Add immarg attributes to patchpoint arguments (#97276)
Browse files Browse the repository at this point in the history
  • Loading branch information
Il-Capitano authored Sep 17, 2024
1 parent 731a683 commit bc8a5d1
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 2 deletions.
8 changes: 6 additions & 2 deletions llvm/include/llvm/IR/Intrinsics.td
Original file line number Diff line number Diff line change
Expand Up @@ -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 ---------------===//
Expand Down
35 changes: 35 additions & 0 deletions llvm/test/Transforms/SimplifyCFG/patchpoint-invalid-sink.ll
Original file line number Diff line number Diff line change
@@ -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, ...)
31 changes: 31 additions & 0 deletions llvm/test/Verifier/intrinsic-immarg.ll
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit bc8a5d1

Please sign in to comment.