Skip to content

Commit a1ee1a9

Browse files
authored
[CodeGen] @llvm.experimental.stackmap make operands immediate (#117932)
This pull request modifies the behavior of the `@llvm.experimental.stackmap` intrinsic to require that its two first operands (`id` and `numShadowBytes`) be **immediate values**. This change ensures that variables cannot be passed as two first arguments to this intrinsic. Related Issue: #115733 ### Testing - Added new test cases to ensure errors are emitted for non-immediate operands. - Ran the full LLVM test suite to verify no regressions were introduced.
1 parent 2dc2261 commit a1ee1a9

File tree

7 files changed

+114
-3
lines changed

7 files changed

+114
-3
lines changed

llvm/docs/StackMaps.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,9 @@ Operands:
112112

113113
The first operand is an ID to be encoded within the stack map. The
114114
second operand is the number of shadow bytes following the
115-
intrinsic. The variable number of operands that follow are the ``live
116-
values`` for which locations will be recorded in the stack map.
115+
intrinsic. These first two operands should be immediate, e.g. cannot
116+
be passed as variables. The variable number of operands that follow are
117+
the ``live values`` for which locations will be recorded in the stack map.
117118

118119
To use this intrinsic as a bare-bones stack map, with no code patching
119120
support, the number of shadow bytes can be set to zero.

llvm/include/llvm/IR/Intrinsics.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1655,7 +1655,7 @@ def int_strip_invariant_group : DefaultAttrsIntrinsic<[llvm_anyptr_ty],
16551655
//
16561656
def int_experimental_stackmap : DefaultAttrsIntrinsic<[],
16571657
[llvm_i64_ty, llvm_i32_ty, llvm_vararg_ty],
1658-
[Throws]>;
1658+
[Throws, ImmArg<ArgIndex<0>>, ImmArg<ArgIndex<1>>]>;
16591659
def int_experimental_patchpoint_void : Intrinsic<[],
16601660
[llvm_i64_ty, llvm_i32_ty,
16611661
llvm_ptr_ty, llvm_i32_ty,
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
; RUN: not llc -mtriple=arm64-linux-gnu < %s 2>&1 | FileCheck %s
2+
; Tests error when we pass non-immediate parameters to @llvm.experiment.stackmap
3+
4+
define void @first_arg() {
5+
; CHECK: immarg operand has non-immediate parameter
6+
entry:
7+
; First operand should be immediate
8+
%id = add i64 0, 0
9+
call void (i64, i32, ...) @llvm.experimental.stackmap(i64 %id, i32 0)
10+
ret void
11+
}
12+
13+
define void @second_arg() {
14+
; CHECK: immarg operand has non-immediate parameter
15+
entry:
16+
; Second operand should be immediate
17+
%numShadowByte = add i32 0, 0
18+
call void (i64, i32, ...) @llvm.experimental.stackmap(i64 1, i32 %numShadowByte)
19+
ret void
20+
}
21+
22+
declare void @llvm.experimental.stackmap(i64, i32, ...)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
; RUN: not llc -verify-machineinstrs -mcpu=ppc -mtriple=powerpc64-unknown-gnu-linux < %s 2>&1 | FileCheck %s
2+
; Tests error when we pass non-immediate parameters to @llvm.experiment.stackmap
3+
4+
define void @first_arg() {
5+
; CHECK: immarg operand has non-immediate parameter
6+
entry:
7+
; First operand should be immediate
8+
%id = add i64 0, 0
9+
call void (i64, i32, ...) @llvm.experimental.stackmap(i64 %id, i32 0)
10+
ret void
11+
}
12+
13+
define void @second_arg() {
14+
; CHECK: immarg operand has non-immediate parameter
15+
entry:
16+
; Second operand should be immediate
17+
%numShadowByte = add i32 0, 0
18+
call void (i64, i32, ...) @llvm.experimental.stackmap(i64 1, i32 %numShadowByte)
19+
ret void
20+
}
21+
22+
declare void @llvm.experimental.stackmap(i64, i32, ...)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
; RUN: not llc -mtriple=riscv64 < %s 2>&1 | FileCheck %s
2+
; Tests error when we pass non-immediate parameters to @llvm.experiment.stackmap
3+
4+
define void @first_arg() {
5+
; CHECK: immarg operand has non-immediate parameter
6+
entry:
7+
; First operand should be immediate
8+
%id = add i64 0, 0
9+
call void (i64, i32, ...) @llvm.experimental.stackmap(i64 %id, i32 0)
10+
ret void
11+
}
12+
13+
define void @second_arg() {
14+
; CHECK: immarg operand has non-immediate parameter
15+
entry:
16+
; Second operand should be immediate
17+
%numShadowByte = add i32 0, 0
18+
call void (i64, i32, ...) @llvm.experimental.stackmap(i64 1, i32 %numShadowByte)
19+
ret void
20+
}
21+
22+
declare void @llvm.experimental.stackmap(i64, i32, ...)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
; RUN: not llc -mtriple=s390x-linux-gnu < %s 2>&1 | FileCheck %s
2+
; Tests error when we pass non-immediate parameters to @llvm.experiment.stackmap
3+
4+
define void @first_arg() {
5+
; CHECK: immarg operand has non-immediate parameter
6+
entry:
7+
; First operand should be immediate
8+
%id = add i64 0, 0
9+
call void (i64, i32, ...) @llvm.experimental.stackmap(i64 %id, i32 0)
10+
ret void
11+
}
12+
13+
define void @second_arg() {
14+
; CHECK: immarg operand has non-immediate parameter
15+
entry:
16+
; Second operand should be immediate
17+
%numShadowByte = add i32 0, 0
18+
call void (i64, i32, ...) @llvm.experimental.stackmap(i64 1, i32 %numShadowByte)
19+
ret void
20+
}
21+
22+
declare void @llvm.experimental.stackmap(i64, i32, ...)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
; RUN: not llc -mtriple=x86_64-apple-darwin -mcpu=corei7 < %s 2>&1 | FileCheck %s
2+
; Tests error when we pass non-immediate parameters to @llvm.experiment.stackmap
3+
4+
define void @first_arg() {
5+
; CHECK: immarg operand has non-immediate parameter
6+
entry:
7+
; First operand should be immediate
8+
%id = add i64 0, 0
9+
call void (i64, i32, ...) @llvm.experimental.stackmap(i64 %id, i32 0)
10+
ret void
11+
}
12+
13+
define void @second_arg() {
14+
; CHECK: immarg operand has non-immediate parameter
15+
entry:
16+
; Second operand should be immediate
17+
%numShadowByte = add i32 0, 0
18+
call void (i64, i32, ...) @llvm.experimental.stackmap(i64 1, i32 %numShadowByte)
19+
ret void
20+
}
21+
22+
declare void @llvm.experimental.stackmap(i64, i32, ...)

0 commit comments

Comments
 (0)