@@ -54,7 +54,7 @@ void decision::operator()(decision_node *entry) {
54
54
" _1" , getvalue_type ({sort_category::Symbol, 0 }, module_)));
55
55
fail_subject_->addIncoming (
56
56
new llvm::BitCastInst (
57
- val, llvm::Type::getInt8PtrTy (ctx_), " " , current_block_),
57
+ val, llvm::PointerType::getUnqual (ctx_), " " , current_block_),
58
58
current_block_);
59
59
fail_pattern_->addIncoming (
60
60
string_literal (" \\ bottom{SortGeneratedTopCell{}}()" ), current_block_);
@@ -72,7 +72,7 @@ llvm::Value *decision::ptr_term(llvm::Value *val) {
72
72
val = allocate_term (val->getType (), current_block_, " kore_alloc_always_gc" );
73
73
}
74
74
return new llvm::BitCastInst (
75
- val, llvm::Type::getInt8PtrTy (ctx_), " " , current_block_);
75
+ val, llvm::PointerType::getUnqual (ctx_), " " , current_block_);
76
76
}
77
77
78
78
bool decision_node::begin_node (decision *d, std::string const &name) {
@@ -490,16 +490,16 @@ void function_node::codegen(decision *d) {
490
490
function_args.push_back (d->string_literal (str));
491
491
}
492
492
function_args.push_back (
493
- llvm::ConstantPointerNull::get (llvm::Type::getInt8PtrTy (d->ctx_ )));
493
+ llvm::ConstantPointerNull::get (llvm::PointerType::getUnqual (d->ctx_ )));
494
494
495
495
auto *call = llvm::CallInst::Create (
496
496
get_or_insert_function (
497
497
d->module_ , " add_match_function" ,
498
498
llvm::FunctionType::get (
499
499
llvm::Type::getVoidTy (d->ctx_ ),
500
- {llvm::Type::getInt8PtrTy (d->ctx_ ),
501
- llvm::Type::getInt8PtrTy (d->ctx_ ),
502
- llvm::Type::getInt8PtrTy (d->ctx_ )},
500
+ {llvm::PointerType::getUnqual (d->ctx_ ),
501
+ llvm::PointerType::getUnqual (d->ctx_ ),
502
+ llvm::PointerType::getUnqual (d->ctx_ )},
503
503
true )),
504
504
function_args, " " , d->current_block_ );
505
505
set_debug_loc (call);
@@ -709,7 +709,7 @@ static void init_choice_buffer(
709
709
std::unordered_set<leaf_node *> leaves;
710
710
dt->preprocess (leaves);
711
711
auto *ty = llvm::ArrayType::get (
712
- llvm::Type::getInt8PtrTy (module ->getContext ()),
712
+ llvm::PointerType::getUnqual (module ->getContext ()),
713
713
dt->get_choice_depth () + 1 );
714
714
auto *choice_buffer = new llvm::AllocaInst (ty, 0 , " choiceBuffer" , block);
715
715
auto *choice_depth = new llvm::AllocaInst (
@@ -928,7 +928,7 @@ static void store_ptrs_for_gc(
928
928
auto *zero
929
929
= llvm::ConstantInt::get (llvm::Type::getInt64Ty (module ->getContext ()), 0 );
930
930
llvm::Type *voidptrptr = llvm::PointerType::getUnqual (
931
- llvm::Type::getInt8PtrTy (module ->getContext ()));
931
+ llvm::PointerType::getUnqual (module ->getContext ()));
932
932
for (unsigned i = 0 ; i < nroots; i++) {
933
933
auto *ptr = llvm::GetElementPtrInst::CreateInBounds (
934
934
root_ty, arr,
@@ -1031,7 +1031,7 @@ static void load_ptrs_for_gc(
1031
1031
std::vector<value_type> const &types,
1032
1032
std::vector<llvm::Value *> const &are_block) {
1033
1033
llvm::Type *voidptrptr = llvm::PointerType::getUnqual (
1034
- llvm::Type::getInt8PtrTy (module ->getContext ()));
1034
+ llvm::PointerType::getUnqual (module ->getContext ()));
1035
1035
unsigned i = 0 ;
1036
1036
for (auto [ptr, pointee_ty] : root_ptrs) {
1037
1037
llvm::Value *loaded = nullptr ;
@@ -1130,24 +1130,18 @@ std::pair<std::vector<llvm::Value *>, llvm::BasicBlock *> step_function_header(
1130
1130
i++;
1131
1131
}
1132
1132
auto *root_ty = llvm::ArrayType::get (
1133
- llvm::Type::getInt8PtrTy (module ->getContext ()), 256 );
1133
+ llvm::PointerType::getUnqual (module ->getContext ()), 256 );
1134
1134
auto *arr = module ->getOrInsertGlobal (" gc_roots" , root_ty);
1135
1135
std::vector<std::pair<llvm::Value *, llvm::Type *>> root_ptrs;
1136
1136
std::vector<llvm::Value *> are_block;
1137
- llvm::Instruction *are_block_val = llvm::CallInst::CreateMalloc (
1137
+ auto *are_block_val = create_malloc (
1138
1138
collect, llvm::Type::getInt64Ty (block->getContext ()),
1139
1139
llvm::Type::getInt1Ty (module ->getContext ()),
1140
1140
llvm::ConstantInt::get (llvm::Type::getInt64Ty (module ->getContext ()), 1 ),
1141
1141
llvm::ConstantInt::get (
1142
1142
llvm::Type::getInt64Ty (module ->getContext ()), nroots),
1143
1143
nullptr );
1144
1144
1145
- #if LLVM_VERSION_MAJOR < 16
1146
- are_block_val->insertAfter (&collect->back ());
1147
- #else
1148
- are_block_val->insertInto (collect, collect->end ());
1149
- #endif
1150
-
1151
1145
store_ptrs_for_gc (
1152
1146
nroots, module , root_ty, arr, are_block_val, collect, roots, types,
1153
1147
ptr_types, root_ptrs, are_block);
@@ -1198,7 +1192,7 @@ std::pair<std::vector<llvm::Value *>, llvm::BasicBlock *> step_function_header(
1198
1192
llvm::FunctionType::get (
1199
1193
llvm::Type::getVoidTy (module ->getContext ()),
1200
1194
{arr->getType (), llvm::Type::getInt8Ty (module ->getContext ()), ptr_ty,
1201
- llvm::Type::getInt1PtrTy (module ->getContext ())},
1195
+ llvm::PointerType::getUnqual (module ->getContext ())},
1202
1196
false ));
1203
1197
auto *call = llvm::CallInst::Create (
1204
1198
kore_collect,
@@ -1379,11 +1373,22 @@ void make_match_reason_function(
1379
1373
llvm::BasicBlock *fail
1380
1374
= llvm::BasicBlock::Create (module ->getContext (), " fail" , match_func);
1381
1375
llvm::PHINode *fail_subject = llvm::PHINode::Create (
1382
- llvm::Type::getInt8PtrTy (module ->getContext ()), 0 , " subject" , fail);
1376
+ llvm::PointerType::getUnqual (module ->getContext ()), 0 , " subject" , fail);
1377
+
1378
+ // The pointer types created here for the failure pattern and sort need to be
1379
+ // given an explicit element type on LLVM 15 (LLVM_VERSION_MAJOR <= 15). This
1380
+ // is because the constants that eventually flow into the Phi nodes still get
1381
+ // type `i8*` on LLVM 15, rather than `ptr` as would be assigned here.
1382
+ //
1383
+ // In newer versions, the string constants also get type `ptr` and these
1384
+ // explicit element types become no-ops that we can remove.
1383
1385
llvm::PHINode *fail_pattern = llvm::PHINode::Create (
1384
- llvm::Type::getInt8PtrTy (module ->getContext ()), 0 , " pattern" , fail);
1386
+ llvm::PointerType::getUnqual (llvm::Type::getInt8Ty (module ->getContext ())),
1387
+ 0 , " pattern" , fail);
1385
1388
llvm::PHINode *fail_sort = llvm::PHINode::Create (
1386
- llvm::Type::getInt8PtrTy (module ->getContext ()), 0 , " sort" , fail);
1389
+ llvm::PointerType::getUnqual (llvm::Type::getInt8Ty (module ->getContext ())),
1390
+ 0 , " sort" , fail);
1391
+
1387
1392
auto *call = llvm::CallInst::Create (
1388
1393
get_or_insert_function (
1389
1394
module , " add_match_fail_reason" ,
0 commit comments