Skip to content

Commit 708c018

Browse files
committed
[IR] Use immarg for preallocated intrinsics (NFC)
Mark the attributes as immarg to indicate that they require a constant integer. This was previously enforced with a manual verifier check.
1 parent 77a3d43 commit 708c018

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

llvm/include/llvm/IR/Intrinsics.td

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -977,8 +977,12 @@ def int_instrprof_mcdc_tvbitmap_update : Intrinsic<[],
977977
[llvm_ptr_ty, llvm_i64_ty,
978978
llvm_i32_ty, llvm_ptr_ty]>;
979979

980-
def int_call_preallocated_setup : DefaultAttrsIntrinsic<[llvm_token_ty], [llvm_i32_ty]>;
981-
def int_call_preallocated_arg : DefaultAttrsIntrinsic<[llvm_ptr_ty], [llvm_token_ty, llvm_i32_ty]>;
980+
def int_call_preallocated_setup
981+
: DefaultAttrsIntrinsic<[llvm_token_ty], [llvm_i32_ty],
982+
[ImmArg<ArgIndex<0>>]>;
983+
def int_call_preallocated_arg
984+
: DefaultAttrsIntrinsic<[llvm_ptr_ty], [llvm_token_ty, llvm_i32_ty],
985+
[ImmArg<ArgIndex<1>>]>;
982986
def int_call_preallocated_teardown : DefaultAttrsIntrinsic<[], [llvm_token_ty]>;
983987

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

llvm/lib/IR/Verifier.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5869,19 +5869,15 @@ 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);
58785876
Check(UseCall != nullptr,
58795877
"Uses of llvm.call.preallocated.setup must be calls");
58805878
Intrinsic::ID IID = UseCall->getIntrinsicID();
58815879
if (IID == Intrinsic::call_preallocated_arg) {
5882-
auto *AllocArgIndex = dyn_cast<ConstantInt>(UseCall->getArgOperand(1));
5883-
Check(AllocArgIndex != nullptr,
5884-
"llvm.call.preallocated.alloc arg index must be a constant");
5880+
auto *AllocArgIndex = cast<ConstantInt>(UseCall->getArgOperand(1));
58855881
auto AllocArgIndexInt = AllocArgIndex->getValue();
58865882
Check(AllocArgIndexInt.sge(0) &&
58875883
AllocArgIndexInt.slt(NumArgs->getValue()),

llvm/test/Verifier/preallocated-invalid.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ 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)

0 commit comments

Comments
 (0)