Skip to content

Commit fd8adf3

Browse files
authored
[IR] Use immarg for preallocated intrinsics (NFC) (#155835)
Mark the attributes as immarg to indicate that they require a constant integer. This was previously enforced with a manual verifier check.
1 parent 0777849 commit fd8adf3

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

llvm/include/llvm/IR/Intrinsics.td

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -960,8 +960,12 @@ def int_instrprof_mcdc_tvbitmap_update : Intrinsic<[],
960960
[llvm_ptr_ty, llvm_i64_ty,
961961
llvm_i32_ty, llvm_ptr_ty]>;
962962

963-
def int_call_preallocated_setup : DefaultAttrsIntrinsic<[llvm_token_ty], [llvm_i32_ty]>;
964-
def int_call_preallocated_arg : DefaultAttrsIntrinsic<[llvm_ptr_ty], [llvm_token_ty, llvm_i32_ty]>;
963+
def int_call_preallocated_setup
964+
: DefaultAttrsIntrinsic<[llvm_token_ty], [llvm_i32_ty],
965+
[ImmArg<ArgIndex<0>>]>;
966+
def int_call_preallocated_arg
967+
: DefaultAttrsIntrinsic<[llvm_ptr_ty], [llvm_token_ty, llvm_i32_ty],
968+
[ImmArg<ArgIndex<1>>]>;
965969
def int_call_preallocated_teardown : DefaultAttrsIntrinsic<[], [llvm_token_ty]>;
966970

967971
// This intrinsic is intentionally undocumented and users shouldn't call it;

llvm/lib/IR/Verifier.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5869,9 +5869,7 @@ void Verifier::visitIntrinsicCall(Intrinsic::ID ID, CallBase &Call) {
58695869
break;
58705870
}
58715871
case Intrinsic::call_preallocated_setup: {
5872-
auto *NumArgs = dyn_cast<ConstantInt>(Call.getArgOperand(0));
5873-
Check(NumArgs != nullptr,
5874-
"llvm.call.preallocated.setup argument must be a constant");
5872+
auto *NumArgs = cast<ConstantInt>(Call.getArgOperand(0));
58755873
bool FoundCall = false;
58765874
for (User *U : Call.users()) {
58775875
auto *UseCall = dyn_cast<CallBase>(U);

llvm/test/Verifier/preallocated-invalid.ll

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,21 @@ define void @preallocated_one_call() {
6565
ret void
6666
}
6767

68-
; CHECK: must be a constant
68+
; CHECK: immarg operand has non-immediate parameter
6969
define void @preallocated_setup_constant() {
7070
%ac = call i32 @blackbox()
7171
%cs = call token @llvm.call.preallocated.setup(i32 %ac)
7272
ret void
7373
}
7474

75+
; CHECK: llvm.call.preallocated.alloc arg index must be a constant
76+
define void @preallocated_arg_constant() {
77+
%ac = call i32 @blackbox()
78+
%cs = call token @llvm.call.preallocated.setup(i32 3)
79+
call token @llvm.call.preallocated.arg(token %cs, i32 %ac)
80+
ret void
81+
}
82+
7583
; CHECK: must be between 0 and corresponding
7684
define void @preallocated_setup_arg_index_in_bounds() {
7785
%cs = call token @llvm.call.preallocated.setup(i32 2)

0 commit comments

Comments
 (0)