From ac9cff855d2c9e3ad92b16eb010db9bcf20d405e Mon Sep 17 00:00:00 2001 From: Dwight Guth Date: Tue, 9 Jul 2024 15:42:03 -0500 Subject: [PATCH] Finalize removal of typed pointers (#1103) Previously we still had some references to typed pointers in .ll files and in API calls that still created typed pointers when working with older versions of LLVM. This led to some invalid bitcode being generated in ways that wasn't necessarily a problem, but which caused problems when I was making changes to that code. This PR is a preliminary to further changes which removes all remaining references to the API constructor for typed pointers and removes all typed pointers from flat bitcode files. --------- Co-authored-by: rv-jenkins --- include/kllvm/codegen/Util.h | 4 +- lib/codegen/CreateStaticTerm.cpp | 18 +-- lib/codegen/CreateTerm.cpp | 75 ++++----- lib/codegen/Decision.cpp | 53 +++---- lib/codegen/DecisionParser.cpp | 10 +- lib/codegen/EmitConfigParser.cpp | 261 ++++++++----------------------- lib/codegen/Util.cpp | 21 +-- runtime/finish_rewriting.ll | 18 +-- runtime/fresh.ll | 42 +++-- runtime/getTag.ll | 10 +- runtime/main/main.ll | 70 ++++----- runtime/move_float.ll | 15 +- runtime/move_int.ll | 15 +- runtime/string_equal.ll | 6 +- runtime/take_steps.ll | 52 +++--- 15 files changed, 241 insertions(+), 429 deletions(-) diff --git a/include/kllvm/codegen/Util.h b/include/kllvm/codegen/Util.h index 58fd53704..0044826d0 100644 --- a/include/kllvm/codegen/Util.h +++ b/include/kllvm/codegen/Util.h @@ -22,9 +22,7 @@ llvm::Constant *get_offset_of_member(llvm::Module *, llvm::StructType *, int); llvm::Function *kore_heap_alloc(std::string const &name, llvm::Module *module); llvm::Instruction *create_malloc( - llvm::BasicBlock *block, llvm::Type *int_ptr_ty, llvm::Type *alloc_ty, - llvm::Value *alloc_size, llvm::Value *array_size, llvm::Function *malloc_f, - std::string const &name = ""); + llvm::BasicBlock *block, llvm::Value *alloc_size, llvm::Function *malloc_f); // getOrInsertFunction on module, aborting on failure template diff --git a/lib/codegen/CreateStaticTerm.cpp b/lib/codegen/CreateStaticTerm.cpp index 0f1f6ed99..4a9a7de64 100644 --- a/lib/codegen/CreateStaticTerm.cpp +++ b/lib/codegen/CreateStaticTerm.cpp @@ -86,8 +86,7 @@ llvm::Constant *create_static_term::not_injection_case( return llvm::ConstantExpr::getBitCast( llvm::ConstantExpr::getInBoundsGetElementPtr( block_type, global_var, idxs), - llvm::PointerType::getUnqual(llvm::StructType::getTypeByName( - module_->getContext(), block_struct))); + llvm::PointerType::getUnqual(module_->getContext())); } std::pair @@ -106,13 +105,11 @@ create_static_term::operator()(kore_pattern *pattern) { false); } if (symbol->get_arguments().empty()) { - llvm::StructType *block_type = llvm::StructType::getTypeByName( - module_->getContext(), block_struct); llvm::Constant *cast = llvm::ConstantExpr::getIntToPtr( llvm::ConstantInt::get( llvm::Type::getInt64Ty(ctx_), (((uint64_t)symbol->get_tag()) << 32) | 1), - llvm::PointerType::getUnqual(block_type)); + llvm::PointerType::getUnqual(module_->getContext())); return std::make_pair(cast, false); } kore_symbol_declaration *symbol_decl @@ -144,6 +141,7 @@ create_static_term::operator()(kore_pattern *pattern) { // NOLINTBEGIN(*-cognitive-complexity) llvm::Constant * create_static_term::create_token(value_type sort, std::string contents) { + auto *ptr_ty = llvm::PointerType::getUnqual(ctx_); switch (sort.cat) { case sort_category::Map: case sort_category::RangeMap: @@ -193,8 +191,7 @@ create_static_term::create_token(value_type sort, std::string contents) { llvm::StructType::getTypeByName( module_->getContext(), int_struct), num_limbs, mp_size, - llvm::ConstantExpr::getPointerCast( - limbs_var, llvm::PointerType::getUnqual(ctx_))))); + llvm::ConstantExpr::getPointerCast(limbs_var, ptr_ty)))); mpz_clear(value); } std::vector idxs @@ -289,8 +286,7 @@ create_static_term::create_token(value_type sort, std::string contents) { expbits, llvm::ConstantStruct::getAnon( {mpfr_prec, mpfr_sign, mpfr_exp, - llvm::ConstantExpr::getPointerCast( - limbs_var, llvm::PointerType::getUnqual(ctx_))})))); + llvm::ConstantExpr::getPointerCast(limbs_var, ptr_ty)})))); mpfr_clear(value); } std::vector idxs @@ -336,9 +332,7 @@ create_static_term::create_token(value_type sort, std::string contents) { string_type, block_header, llvm::ConstantDataArray::getString(ctx_, contents, false))); } - return llvm::ConstantExpr::getPointerCast( - global, llvm::PointerType::getUnqual(llvm::StructType::getTypeByName( - module_->getContext(), block_struct))); + return llvm::ConstantExpr::getPointerCast(global, ptr_ty); } case sort_category::SetIter: case sort_category::MapIter: diff --git a/lib/codegen/CreateTerm.cpp b/lib/codegen/CreateTerm.cpp index 41189fc8a..5f7016ded 100644 --- a/lib/codegen/CreateTerm.cpp +++ b/lib/codegen/CreateTerm.cpp @@ -76,20 +76,20 @@ target triple = "{triple}" ; We also define the following LLVM structure types: %string = type { %blockheader, [0 x i8] } ; 10-bit layout, 4-bit gc flags, 10 unused bits, 40-bit length (or buffer capacity for string pointed by stringbuffers), bytes -%stringbuffer = type { i64, i64, %string* } ; 10-bit layout, 4-bit gc flags, 10 unused bits, 40-bit length, string length, current contents -%map = type { { i8 *, i64 } } ; immer::map -%rangemap = type { { { { { i32 (...)**, i32, i64 }*, { { i32 (...)**, i32, i32 }* } } } } } ; rng_map::RangeMap -%set = type { { i8 *, i64 } } ; immer::set -%iter = type { { i8 *, i8 *, i32, [14 x i8**] }, { { i8 *, i64 } } } ; immer::map_iter / immer::set_iter -%list = type { { i64, i32, i8 *, i8 * } } ; immer::flex_vector -%mpz = type { i32, i32, i64 * } ; mpz_t +%stringbuffer = type { i64, i64, ptr } ; 10-bit layout, 4-bit gc flags, 10 unused bits, 40-bit length, string length, current contents +%map = type { { ptr, i64 } } ; immer::map +%rangemap = type { { { { ptr, { ptr } } } } } ; rng_map::RangeMap +%set = type { { ptr, i64 } } ; immer::set +%iter = type { { ptr, ptr, i32, [14 x ptr] }, { { ptr, i64 } } } ; immer::map_iter / immer::set_iter +%list = type { { i64, i32, ptr, ptr } } ; immer::flex_vector +%mpz = type { i32, i32, ptr } ; mpz_t %mpz_hdr = type { %blockheader, %mpz } ; 10-bit layout, 4-bit gc flags, 10 unused bits, 40-bit length, mpz_t -%floating = type { i64, { i64, i32, i64, i64 * } } ; exp, mpfr_t +%floating = type { i64, { i64, i32, i64, ptr } } ; exp, mpfr_t %floating_hdr = type { %blockheader, %floating } ; 10-bit layout, 4-bit gc flags, 10 unused bits, 40-bit length, floating %blockheader = type { i64 } -%block = type { %blockheader, [0 x i64 *] } ; 16-bit layout, 8-bit length, 32-bit tag, children +%block = type { %blockheader, [0 x ptr] } ; 16-bit layout, 8-bit length, 32-bit tag, children -%layout = type { i8, %layoutitem* } ; number of children, array of children +%layout = type { i8, ptr } ; number of children, array of children %layoutitem = type { i64, i16 } ; offset, category ; The layout of a block uniquely identifies the categories of its children as @@ -111,8 +111,8 @@ target triple = "{triple}" ; %layoutN = type { %blockheader, [0 x i64 *], %map, %mpz *, %block * } ; Interface to the configuration parser -declare %block* @parse_configuration(i8*) -declare void @print_configuration(i8 *, %block *) +declare ptr @parse_configuration(ptr) +declare void @print_configuration(ptr, ptr) )LLVM"; return target_dependent + rest; } @@ -147,7 +147,9 @@ llvm::Type *get_param_type(value_type sort, llvm::Module *module) { case sort_category::Map: case sort_category::RangeMap: case sort_category::List: - case sort_category::Set: type = llvm::PointerType::getUnqual(type); break; + case sort_category::Set: + type = llvm::PointerType::getUnqual(module->getContext()); + break; default: break; } return type; @@ -168,22 +170,15 @@ llvm::Type *getvalue_type(value_type sort, llvm::Module *module) { return llvm::StructType::getTypeByName(module->getContext(), list_struct); case sort_category::Set: return llvm::StructType::getTypeByName(module->getContext(), set_struct); - case sort_category::Int: - return llvm::PointerType::getUnqual( - llvm::StructType::getTypeByName(module->getContext(), int_struct)); - case sort_category::Float: - return llvm::PointerType::getUnqual( - llvm::StructType::getTypeByName(module->getContext(), float_struct)); - case sort_category::StringBuffer: - return llvm::PointerType::getUnqual( - llvm::StructType::getTypeByName(module->getContext(), buffer_struct)); case sort_category::Bool: return llvm::Type::getInt1Ty(module->getContext()); case sort_category::MInt: return llvm::IntegerType::get(module->getContext(), sort.bits); + case sort_category::Int: + case sort_category::Float: + case sort_category::StringBuffer: case sort_category::Symbol: case sort_category::Variable: - return llvm::PointerType::getUnqual( - llvm::StructType::getTypeByName(module->getContext(), block_struct)); + return llvm::PointerType::getUnqual(module->getContext()); case sort_category::MapIter: case sort_category::SetIter: case sort_category::Uncomputed: abort(); @@ -268,8 +263,7 @@ llvm::Value *allocate_term( llvm::Type *alloc_type, llvm::Value *len, llvm::BasicBlock *block, char const *alloc_fn) { auto *malloc = create_malloc( - block, llvm::Type::getInt64Ty(block->getContext()), alloc_type, len, - nullptr, kore_heap_alloc(alloc_fn, block->getModule())); + block, len, kore_heap_alloc(alloc_fn, block->getModule())); set_debug_loc(malloc); return malloc; @@ -340,6 +334,7 @@ std::string escape(std::string const &str) { llvm::Value *create_term::create_hook( kore_composite_pattern *hook_att, kore_composite_pattern *pattern, std::string const &location_stack) { + auto *ptr_ty = llvm::PointerType::getUnqual(ctx_); assert(hook_att->get_arguments().size() == 1); auto *str_pattern = dynamic_cast(hook_att->get_arguments()[0].get()); @@ -513,9 +508,8 @@ llvm::Value *create_term::create_hook( auto *result = llvm::CallInst::Create( get_or_insert_function( module_, "hook_MINT_import", - getvalue_type({sort_category::Int, 0}, module_), - llvm::PointerType::getUnqual(ctx_), llvm::Type::getInt64Ty(ctx_), - llvm::Type::getInt1Ty(ctx_)), + getvalue_type({sort_category::Int, 0}, module_), ptr_ty, + llvm::Type::getInt64Ty(ctx_), llvm::Type::getInt1Ty(ctx_)), {ptr, llvm::ConstantInt::get(llvm::Type::getInt64Ty(ctx_), cat.bits), llvm::ConstantInt::getFalse(ctx_)}, "hook_MINT_uvalue", current_block_); @@ -565,9 +559,8 @@ llvm::Value *create_term::create_hook( auto *result = llvm::CallInst::Create( get_or_insert_function( module_, "hook_MINT_import", - getvalue_type({sort_category::Int, 0}, module_), - llvm::PointerType::getUnqual(ctx_), llvm::Type::getInt64Ty(ctx_), - llvm::Type::getInt1Ty(ctx_)), + getvalue_type({sort_category::Int, 0}, module_), ptr_ty, + llvm::Type::getInt64Ty(ctx_), llvm::Type::getInt1Ty(ctx_)), {ptr, llvm::ConstantInt::get(llvm::Type::getInt64Ty(ctx_), cat.bits), llvm::ConstantInt::getTrue(ctx_)}, "hook_MINT_svalue", current_block_); @@ -582,7 +575,7 @@ llvm::Value *create_term::create_hook( auto *type = getvalue_type(cat, module_); llvm::Instruction *ptr = llvm::CallInst::Create( get_or_insert_function( - module_, "hook_MINT_export", llvm::PointerType::getUnqual(ctx_), + module_, "hook_MINT_export", ptr_ty, getvalue_type({sort_category::Int, 0}, module_), llvm::Type::getInt64Ty(ctx_)), {mpz, llvm::ConstantInt::get(llvm::Type::getInt64Ty(ctx_), cat.bits)}, @@ -784,7 +777,7 @@ llvm::Value *create_term::create_function_call( types.insert(types.begin(), alloc_sret->getType()); return_type = llvm::Type::getVoidTy(ctx_); } else if (collection) { - return_type = llvm::PointerType::getUnqual(return_type); + return_type = llvm::PointerType::getUnqual(ctx_); } llvm::FunctionType *func_type @@ -868,8 +861,7 @@ llvm::Value *create_term::not_injection_case( new llvm::StoreInst(child_value, child_ptr, current_block_); } - auto *block_ptr = llvm::PointerType::getUnqual( - llvm::StructType::getTypeByName(module_->getContext(), block_struct)); + auto *block_ptr = llvm::PointerType::getUnqual(module_->getContext()); auto *bitcast = new llvm::BitCastInst(block, block_ptr, "", current_block_); if (symbol_decl->attributes().contains(attribute_set::key::Binder)) { auto *call = llvm::CallInst::Create( @@ -1056,6 +1048,7 @@ bool make_function( std::vector param_types; std::vector param_names; std::vector debug_args; + auto *ptr_ty = llvm::PointerType::getUnqual(module->getContext()); for (auto &entry : vars) { auto *sort = dynamic_cast(entry.second->get_sort().get()); @@ -1070,9 +1063,7 @@ bool make_function( case sort_category::Map: case sort_category::RangeMap: case sort_category::List: - case sort_category::Set: - param_type = llvm::PointerType::getUnqual(param_type); - break; + case sort_category::Set: param_type = ptr_ty; break; default: break; } @@ -1086,9 +1077,7 @@ bool make_function( case sort_category::Map: case sort_category::RangeMap: case sort_category::List: - case sort_category::Set: - return_type = llvm::PointerType::getUnqual(return_type); - break; + case sort_category::Set: return_type = ptr_ty; break; default: break; } llvm::FunctionType *func_type @@ -1203,7 +1192,7 @@ std::string make_apply_rule_function( case sort_category::RangeMap: case sort_category::List: case sort_category::Set: - param_type = llvm::PointerType::getUnqual(param_type); + param_type = llvm::PointerType::getUnqual(module->getContext()); break; default: break; } diff --git a/lib/codegen/Decision.cpp b/lib/codegen/Decision.cpp index d9e08fe88..db72d96ab 100644 --- a/lib/codegen/Decision.cpp +++ b/lib/codegen/Decision.cpp @@ -146,6 +146,7 @@ void switch_node::codegen(decision *d) { if (begin_node(d, "switch" + name_)) { return; } + auto *ptr_ty = llvm::PointerType::getUnqual(d->ctx_); llvm::Value *val = d->load(std::make_pair(name_, type_)); llvm::Value *ptr_val = nullptr; if (d->fail_pattern_) { @@ -235,8 +236,7 @@ void switch_node::codegen(decision *d) { int offset = 0; llvm::StructType *block_type = get_block_type( d->module_, d->definition_, switch_case.get_constructor()); - auto *cast = new llvm::BitCastInst( - val, llvm::PointerType::getUnqual(block_type), "", d->current_block_); + auto *cast = new llvm::BitCastInst(val, ptr_ty, "", d->current_block_); kore_symbol_declaration *symbol_decl = d->definition_->get_symbol_declarations().at( switch_case.get_constructor()->get_name()); @@ -268,9 +268,7 @@ void switch_node::codegen(decision *d) { binding.first.substr(0, max_name_length), d->current_block_); break; } - auto *block_ptr - = llvm::PointerType::getUnqual(llvm::StructType::getTypeByName( - d->module_->getContext(), block_struct)); + auto *block_ptr = ptr_ty; if (symbol_decl->attributes().contains(attribute_set::key::Binder)) { if (offset == 0) { renamed = llvm::CallInst::Create( @@ -492,17 +490,14 @@ void function_node::codegen(decision *d) { auto str = legacy_value_type_to_string(cat); function_args.push_back(d->string_literal(str)); } - function_args.push_back( - llvm::ConstantPointerNull::get(llvm::PointerType::getUnqual(d->ctx_))); + auto *ptr_ty = llvm::PointerType::getUnqual(d->ctx_); + function_args.push_back(llvm::ConstantPointerNull::get(ptr_ty)); auto *call = llvm::CallInst::Create( get_or_insert_function( d->module_, "add_match_function", llvm::FunctionType::get( - llvm::Type::getVoidTy(d->ctx_), - {llvm::PointerType::getUnqual(d->ctx_), - llvm::PointerType::getUnqual(d->ctx_), - llvm::PointerType::getUnqual(d->ctx_)}, + llvm::Type::getVoidTy(d->ctx_), {ptr_ty, ptr_ty, ptr_ty}, true)), function_args, "", d->current_block_); set_debug_loc(call); @@ -783,7 +778,7 @@ void make_eval_or_anywhere_function( case sort_category::RangeMap: case sort_category::List: case sort_category::Set: - args.push_back(llvm::PointerType::getUnqual(getvalue_type(cat, module))); + args.push_back(llvm::PointerType::getUnqual(module->getContext())); cats.push_back(cat); break; default: @@ -842,8 +837,7 @@ void abort_when_stuck( symbol = d->get_all_symbols().at(ast_to_string(*symbol)); auto *block_type = get_block_type(module, d, symbol); llvm::Value *ptr = nullptr; - auto *block_ptr = llvm::PointerType::getUnqual( - llvm::StructType::getTypeByName(module->getContext(), block_struct)); + auto *block_ptr = llvm::PointerType::getUnqual(module->getContext()); if (symbol->get_arguments().empty()) { ptr = llvm::ConstantExpr::getIntToPtr( llvm::ConstantInt::get( @@ -954,7 +948,7 @@ static void store_ptrs_for_gc( llvm::Type::getInt64Ty(module->getContext()), i)}, "", collect); auto *casted = new llvm::BitCastInst( - ptr, llvm::PointerType::getUnqual(ptr_types[i]), "", collect); + ptr, llvm::PointerType::getUnqual(module->getContext()), "", collect); new llvm::StoreInst(roots[i], casted, collect); root_ptrs.emplace_back(casted, ptr_types[i]); } @@ -982,6 +976,7 @@ std::pair, llvm::BasicBlock *> step_function_header( unsigned ordinal, llvm::Module *module, kore_definition *definition, llvm::BasicBlock *block, llvm::BasicBlock *stuck, std::vector args, std::vector const &types) { + auto *ptr_ty = llvm::PointerType::getUnqual(module->getContext()); auto *finished = get_or_insert_function( module, "finished_rewriting", llvm::FunctionType::get( @@ -1015,8 +1010,7 @@ std::pair, llvm::BasicBlock *> step_function_header( case sort_category::List: case sort_category::Set: nroots++; - ptr_types.push_back( - llvm::PointerType::getUnqual(getvalue_type(type, module))); + ptr_types.push_back(ptr_ty); roots.push_back(args[i]); break; case sort_category::Int: @@ -1036,8 +1030,7 @@ std::pair, llvm::BasicBlock *> step_function_header( } i++; } - auto *root_ty = llvm::ArrayType::get( - llvm::PointerType::getUnqual(module->getContext()), 256); + auto *root_ty = llvm::ArrayType::get(ptr_ty, 256); auto *arr = module->getOrInsertGlobal("gc_roots", root_ty); std::vector> root_ptrs; @@ -1085,15 +1078,12 @@ std::pair, llvm::BasicBlock *> step_function_header( if (!global_var->hasInitializer()) { global_var->setInitializer(layout_arr); } - auto *ptr_ty = llvm::PointerType::getUnqual(llvm::ArrayType::get( - llvm::StructType::getTypeByName(module->getContext(), layoutitem_struct), - 0)); auto *kore_collect = get_or_insert_function( module, "kore_collect", llvm::FunctionType::get( llvm::Type::getVoidTy(module->getContext()), {arr->getType(), llvm::Type::getInt8Ty(module->getContext()), ptr_ty, - llvm::PointerType::getUnqual(module->getContext())}, + ptr_ty}, false)); auto *call = llvm::CallInst::Create( kore_collect, @@ -1274,8 +1264,9 @@ void make_match_reason_function( = llvm::BasicBlock::Create(module->getContext(), "pre_stuck", match_func); llvm::BasicBlock *fail = llvm::BasicBlock::Create(module->getContext(), "fail", match_func); - llvm::PHINode *fail_subject = llvm::PHINode::Create( - llvm::PointerType::getUnqual(module->getContext()), 0, "subject", fail); + auto *ptr_ty = llvm::PointerType::getUnqual(module->getContext()); + llvm::PHINode *fail_subject + = llvm::PHINode::Create(ptr_ty, 0, "subject", fail); // The pointer types created here for the failure pattern and sort need to be // given an explicit element type on LLVM 15 (LLVM_VERSION_MAJOR <= 15). This @@ -1284,12 +1275,9 @@ void make_match_reason_function( // // In newer versions, the string constants also get type `ptr` and these // explicit element types become no-ops that we can remove. - llvm::PHINode *fail_pattern = llvm::PHINode::Create( - llvm::PointerType::getUnqual(llvm::Type::getInt8Ty(module->getContext())), - 0, "pattern", fail); - llvm::PHINode *fail_sort = llvm::PHINode::Create( - llvm::PointerType::getUnqual(llvm::Type::getInt8Ty(module->getContext())), - 0, "sort", fail); + llvm::PHINode *fail_pattern + = llvm::PHINode::Create(ptr_ty, 0, "pattern", fail); + llvm::PHINode *fail_sort = llvm::PHINode::Create(ptr_ty, 0, "sort", fail); auto *call = llvm::CallInst::Create( get_or_insert_function( @@ -1373,8 +1361,7 @@ void make_step_function( case sort_category::RangeMap: case sort_category::List: case sort_category::Set: - arg_types.push_back( - llvm::PointerType::getUnqual(getvalue_type(cat, module))); + arg_types.push_back(llvm::PointerType::getUnqual(module->getContext())); break; default: arg_types.push_back(getvalue_type(cat, module)); break; } diff --git a/lib/codegen/DecisionParser.cpp b/lib/codegen/DecisionParser.cpp index 149692136..5297b9e46 100644 --- a/lib/codegen/DecisionParser.cpp +++ b/lib/codegen/DecisionParser.cpp @@ -230,9 +230,7 @@ class dt_preprocessor { return make_iterator_node::create( collection, type, collection + "_iter", - llvm::PointerType::getUnqual( - llvm::StructType::getTypeByName(mod_->getContext(), "iter")), - hook_name, child); + llvm::PointerType::getUnqual(mod_->getContext()), hook_name, child); } decision_node *iter_next(yaml_node_t *node) { @@ -244,10 +242,8 @@ class dt_preprocessor { auto *child = (*this)(get(node, "next")); return iter_next_node::create( - iterator, - llvm::PointerType::getUnqual( - llvm::StructType::getTypeByName(mod_->getContext(), "iter")), - binding, type, function, child); + iterator, llvm::PointerType::getUnqual(mod_->getContext()), binding, + type, function, child); } decision_node *switch_case(kind kind, yaml_node_t *node) { diff --git a/lib/codegen/EmitConfigParser.cpp b/lib/codegen/EmitConfigParser.cpp index e8f770db8..ea68e84b1 100644 --- a/lib/codegen/EmitConfigParser.cpp +++ b/lib/codegen/EmitConfigParser.cpp @@ -70,10 +70,9 @@ static llvm::Constant *get_symbol_name_ptr( static llvm::Function *get_strcmp(llvm::Module *module) { llvm::LLVMContext &ctx = module->getContext(); + auto *ptr_ty = llvm::PointerType::getUnqual(ctx); auto *type = llvm::FunctionType::get( - llvm::Type::getInt32Ty(ctx), - {llvm::PointerType::getUnqual(ctx), llvm::PointerType::getUnqual(ctx)}, - false); + llvm::Type::getInt32Ty(ctx), {ptr_ty, ptr_ty}, false); return get_or_insert_function(module, "strcmp", type); } @@ -181,8 +180,7 @@ static void emit_data_for_symbol( std::vector arg_types; arg_types.push_back(llvm::Type::getInt32Ty(ctx)); if (is_eval) { - auto *ty = llvm::PointerType::getUnqual( - llvm::ArrayType::get(llvm::PointerType::getUnqual(ctx), 0)); + auto *ty = llvm::PointerType::getUnqual(ctx); arg_types.push_back(ty); } auto *func = get_or_insert_function( @@ -313,20 +311,19 @@ static llvm::Value *get_arg_value( llvm::LLVMContext &ctx = mod->getContext(); llvm::Constant *zero = llvm::ConstantInt::get(llvm::Type::getInt64Ty(ctx), 0); - auto *i8_ptr_ty = llvm::PointerType::getUnqual(ctx); + auto *ptr_ty = llvm::PointerType::getUnqual(ctx); auto *addr = llvm::GetElementPtrInst::Create( - llvm::ArrayType::get(i8_ptr_ty, 0), arguments_array, + llvm::ArrayType::get(ptr_ty, 0), arguments_array, {zero, llvm::ConstantInt::get(llvm::Type::getInt64Ty(ctx), idx)}, "", case_block); - llvm::Value *arg = new llvm::LoadInst(i8_ptr_ty, addr, "", case_block); + llvm::Value *arg = new llvm::LoadInst(ptr_ty, addr, "", case_block); switch (cat.cat) { case sort_category::Bool: case sort_category::MInt: { auto *val_ty = getvalue_type(cat, mod); - auto *cast = new llvm::BitCastInst( - arg, llvm::PointerType::getUnqual(val_ty), "", case_block); + auto *cast = new llvm::BitCastInst(arg, ptr_ty, "", case_block); auto *load = new llvm::LoadInst(val_ty, cast, "", case_block); arg = load; break; @@ -335,9 +332,7 @@ static llvm::Value *get_arg_value( case sort_category::RangeMap: case sort_category::List: case sort_category::Set: - arg = new llvm::BitCastInst( - arg, llvm::PointerType::getUnqual(getvalue_type(cat, mod)), "", - case_block); + arg = new llvm::BitCastInst(arg, ptr_ty, "", case_block); break; case sort_category::Int: case sort_category::Float: @@ -378,6 +373,7 @@ static std::pair get_eval( llvm::Value *retval = nullptr; value_type cat = dynamic_cast(symbol->get_sort().get()) ->get_category(def); + auto *ptr_ty = llvm::PointerType::getUnqual(ctx); switch (cat.cat) { case sort_category::Int: case sort_category::Float: @@ -389,19 +385,17 @@ static std::pair get_eval( case sort_category::List: case sort_category::Set: retval = new llvm::BitCastInst( - result, llvm::PointerType::getUnqual(ctx), "", - creator.get_current_block()); + result, ptr_ty, "", creator.get_current_block()); break; case sort_category::Bool: case sort_category::MInt: { auto *malloc = create_malloc( - creator.get_current_block(), llvm::Type::getInt64Ty(ctx), - result->getType(), llvm::ConstantExpr::getSizeOf(result->getType()), - nullptr, nullptr); + creator.get_current_block(), + llvm::ConstantExpr::getSizeOf(result->getType()), + get_or_insert_function(mod, "malloc", ptr_ty, ptr_ty)); new llvm::StoreInst(result, malloc, creator.get_current_block()); retval = new llvm::BitCastInst( - malloc, llvm::PointerType::getUnqual(ctx), "", - creator.get_current_block()); + malloc, ptr_ty, "", creator.get_current_block()); break; } case sort_category::MapIter: @@ -482,22 +476,18 @@ emit_get_tag_for_fresh_sort(kore_definition *definition, llvm::Module *module) { static void emit_get_token(kore_definition *definition, llvm::Module *module) { llvm::LLVMContext &ctx = module->getContext(); + auto *ptr_ty = llvm::PointerType::getUnqual(ctx); auto *get_token_type = llvm::FunctionType::get( - llvm::PointerType::getUnqual(ctx), - {llvm::PointerType::getUnqual(ctx), llvm::Type::getInt64Ty(ctx), - llvm::PointerType::getUnqual(ctx)}, - false); + ptr_ty, {ptr_ty, llvm::Type::getInt64Ty(ctx), ptr_ty}, false); auto *func = get_or_insert_function(module, "get_token", get_token_type); auto *current_block = llvm::BasicBlock::Create(ctx, ""); auto *merge_block = llvm::BasicBlock::Create(ctx, "exit"); auto *phi = llvm::PHINode::Create( - llvm::PointerType::getUnqual(ctx), - definition->get_sort_declarations().size(), "phi", merge_block); + ptr_ty, definition->get_sort_declarations().size(), "phi", merge_block); auto const &sorts = definition->get_sort_declarations(); llvm::Function *strcmp = get_strcmp(module); llvm::Function *string_equal = get_or_insert_function( - module, "string_equal", llvm::Type::getInt1Ty(ctx), - llvm::PointerType::getUnqual(ctx), llvm::PointerType::getUnqual(ctx), + module, "string_equal", llvm::Type::getInt1Ty(ctx), ptr_ty, ptr_ty, llvm::Type::getInt64Ty(ctx), llvm::Type::getInt64Ty(ctx)); llvm::Constant *zero = llvm::ConstantInt::get(llvm::Type::getInt64Ty(ctx), 0); llvm::Constant *zero32 @@ -558,11 +548,10 @@ static void emit_get_token(kore_definition *definition, llvm::Module *module) { {func->arg_begin() + 2, ptr, func->arg_begin() + 1, len}, "", case_block); auto *malloc = create_malloc( - case_block, llvm::Type::getInt64Ty(ctx), compare->getType(), - llvm::ConstantExpr::getSizeOf(compare->getType()), nullptr, nullptr); + case_block, llvm::ConstantExpr::getSizeOf(compare->getType()), + get_or_insert_function(module, "malloc", ptr_ty, ptr_ty)); new llvm::StoreInst(compare, malloc, case_block); - auto *result = new llvm::BitCastInst( - malloc, llvm::PointerType::getUnqual(ctx), "", case_block); + auto *result = new llvm::BitCastInst(malloc, ptr_ty, "", case_block); phi->addIncoming(result, case_block); llvm::BranchInst::Create(merge_block, case_block); break; @@ -573,13 +562,10 @@ static void emit_get_token(kore_definition *definition, llvm::Module *module) { llvm::Value *term = allocate_term(float_ty, case_block, "kore_alloc_floating"); llvm::Function *init_float = get_or_insert_function( - module, "init_float", llvm::Type::getVoidTy(ctx), - llvm::PointerType::getUnqual(float_ty), - llvm::PointerType::getUnqual(ctx)); + module, "init_float", llvm::Type::getVoidTy(ctx), ptr_ty, ptr_ty); llvm::CallInst::Create( init_float, {term, func->arg_begin() + 2}, "", case_block); - auto *cast = new llvm::BitCastInst( - term, llvm::PointerType::getUnqual(ctx), "", case_block); + auto *cast = new llvm::BitCastInst(term, ptr_ty, "", case_block); phi->addIncoming(cast, case_block); llvm::BranchInst::Create(merge_block, case_block); break; @@ -602,8 +588,7 @@ static void emit_get_token(kore_definition *definition, llvm::Module *module) { llvm::Type::getInt8Ty(ctx), func->arg_begin() + 2, {one}, "", if_is_plus); llvm::BranchInst::Create(else_no_plus, if_is_plus); - auto *phi_str = llvm::PHINode::Create( - llvm::PointerType::getUnqual(ctx), 2, "", else_no_plus); + auto *phi_str = llvm::PHINode::Create(ptr_ty, 2, "", else_no_plus); phi_str->addIncoming(func->arg_begin() + 2, case_block); phi_str->addIncoming(pruned, if_is_plus); case_block = else_no_plus; @@ -612,9 +597,8 @@ static void emit_get_token(kore_definition *definition, llvm::Module *module) { llvm::Value *term = allocate_term(int_ty, case_block, "kore_alloc_integer"); llvm::Function *mpz_init_set = get_or_insert_function( - module, "__gmpz_init_set_str", llvm::Type::getInt32Ty(ctx), - llvm::PointerType::getUnqual(int_ty), - llvm::PointerType::getUnqual(ctx), llvm::Type::getInt32Ty(ctx)); + module, "__gmpz_init_set_str", llvm::Type::getInt32Ty(ctx), ptr_ty, + ptr_ty, llvm::Type::getInt32Ty(ctx)); auto *call = llvm::CallInst::Create( mpz_init_set, {term, phi_str, @@ -624,8 +608,7 @@ static void emit_get_token(kore_definition *definition, llvm::Module *module) { *case_block, llvm::CmpInst::ICMP_EQ, call, zero32); auto *abort_block = llvm::BasicBlock::Create(ctx, "invalid_int", func); add_abort(abort_block, module); - auto *cast = new llvm::BitCastInst( - term, llvm::PointerType::getUnqual(ctx), "", case_block); + auto *cast = new llvm::BitCastInst(term, ptr_ty, "", case_block); llvm::BranchInst::Create(merge_block, abort_block, icmp, case_block); phi->addIncoming(cast, case_block); break; @@ -655,8 +638,7 @@ static void emit_get_token(kore_definition *definition, llvm::Module *module) { llvm::Type::getInt64Ty(ctx), block_size, "", current_block); auto *block_alloc_size = llvm::BinaryOperator::Create( llvm::Instruction::Sub, block_size_val, - llvm::ConstantExpr::getSizeOf(llvm::PointerType::getUnqual(ctx)), "", - current_block); + llvm::ConstantExpr::getSizeOf(ptr_ty), "", current_block); auto *icmp = new llvm::ICmpInst( *current_block, llvm::CmpInst::ICMP_UGT, len, block_alloc_size); auto *mask = llvm::SelectInst::Create( @@ -668,9 +650,7 @@ static void emit_get_token(kore_definition *definition, llvm::Module *module) { llvm::Instruction::Or, func->arg_begin() + 1, mask, "", current_block); new llvm::StoreInst(hdr_ored, hdr_ptr, current_block); llvm::Function *memcpy = get_or_insert_function( - module, "memcpy", llvm::PointerType::getUnqual(ctx), - llvm::PointerType::getUnqual(ctx), llvm::PointerType::getUnqual(ctx), - llvm::Type::getInt64Ty(ctx)); + module, "memcpy", ptr_ty, ptr_ty, ptr_ty, llvm::Type::getInt64Ty(ctx)); auto *str_ptr = llvm::GetElementPtrInst::CreateInBounds( string_type, block, {zero, llvm::ConstantInt::get(llvm::Type::getInt32Ty(ctx), 1), zero}, "", @@ -678,114 +658,25 @@ static void emit_get_token(kore_definition *definition, llvm::Module *module) { llvm::CallInst::Create( memcpy, {str_ptr, func->arg_begin() + 2, func->arg_begin() + 1}, "", current_block); - auto *cast = new llvm::BitCastInst( - block, llvm::PointerType::getUnqual(ctx), "", current_block); + auto *cast = new llvm::BitCastInst(block, ptr_ty, "", current_block); llvm::BranchInst::Create(merge_block, current_block); phi->addIncoming(cast, current_block); llvm::ReturnInst::Create(ctx, phi, merge_block); merge_block->insertInto(func); } -static llvm::PointerType *make_writer_type(llvm::LLVMContext &ctx) { - std::string const name = "writer"; - static auto types = std::map{}; - - if (types.find(&ctx) == types.end()) { - types[&ctx] - = llvm::PointerType::getUnqual(llvm::StructType::create(ctx, name)); - } - - return types.at(&ctx); -} - -static llvm::PointerType *make_visitor_type( - llvm::LLVMContext &ctx, llvm::Type *file, llvm::Type *item, int num_strs, - int num_bools, bool is_serialize) { - std::vector types; - types.push_back(file); - types.push_back(item); - for (int i = 0; i < num_strs; i++) { - if (is_serialize) { - types.push_back(llvm::Type::getInt32Ty(ctx)); - } else { - types.push_back(llvm::PointerType::getUnqual(ctx)); - } - } - for (int i = 0; i < num_bools; i++) { - types.push_back(llvm::Type::getInt1Ty(ctx)); - } - - if (!is_serialize) { - types.push_back(llvm::PointerType::getUnqual(ctx)); - } - - return llvm::PointerType::getUnqual( - llvm::FunctionType::get(llvm::Type::getVoidTy(ctx), types, false)); -} - static llvm::StructType *make_packed_visitor_structure_type( llvm::LLVMContext &ctx, llvm::Module *module, bool is_serialize) { std::string const name = is_serialize ? "serialize_visitor" : "visitor"; static auto types = std::map{}; - auto *file = make_writer_type(ctx); + auto *ptr_ty = llvm::PointerType::getUnqual(ctx); if (types.find(&ctx) == types.end()) { - auto element_types = std::vector{ - {make_visitor_type( - ctx, file, getvalue_type({sort_category::Symbol, 0}, module), 1, 1, - is_serialize), - make_visitor_type( - ctx, file, - llvm::PointerType::getUnqual( - getvalue_type({sort_category::Map, 0}, module)), - 3, 0, is_serialize), - make_visitor_type( - ctx, file, - llvm::PointerType::getUnqual( - getvalue_type({sort_category::List, 0}, module)), - 3, 0, is_serialize), - make_visitor_type( - ctx, file, - llvm::PointerType::getUnqual( - getvalue_type({sort_category::Set, 0}, module)), - 3, 0, is_serialize), - make_visitor_type( - ctx, file, getvalue_type({sort_category::Int, 0}, module), 1, 0, - is_serialize), - make_visitor_type( - ctx, file, getvalue_type({sort_category::Float, 0}, module), 1, 0, - is_serialize), - make_visitor_type( - ctx, file, getvalue_type({sort_category::Bool, 0}, module), 1, 0, - is_serialize), - make_visitor_type( - ctx, file, getvalue_type({sort_category::StringBuffer, 0}, module), - 1, 0, is_serialize), - is_serialize ? llvm::PointerType::getUnqual(llvm::FunctionType::get( - llvm::Type::getVoidTy(ctx), - {file, llvm::PointerType::getUnqual(ctx), - llvm::Type::getInt64Ty(ctx), llvm::PointerType::getUnqual(ctx), - llvm::PointerType::getUnqual(ctx)}, - false)) - : llvm::PointerType::getUnqual(llvm::FunctionType::get( - llvm::Type::getVoidTy(ctx), - {file, llvm::PointerType::getUnqual(ctx), - llvm::Type::getInt64Ty(ctx), - llvm::Type::getInt32Ty(ctx)}, - false))}}; + auto element_types = std::vector(10, ptr_ty); if (!is_serialize) { - element_types.push_back( - llvm::PointerType::getUnqual(llvm::FunctionType::get( - llvm::Type::getVoidTy(ctx), - {file, llvm::PointerType::getUnqual(ctx)}, false))); + element_types.push_back(ptr_ty); } - element_types.push_back(make_visitor_type( - ctx, file, - llvm::PointerType::getUnqual( - getvalue_type({sort_category::RangeMap, 0}, module)), - 3, 0, is_serialize)); - auto *struct_ty = llvm::StructType::create(ctx, element_types, name); types[&ctx] = struct_ty; } @@ -804,20 +695,19 @@ static void emit_traversal( auto *block_ty = get_block_type(module); arg_types.push_back(block_ty->getPointerTo()); + auto *ptr_ty = llvm::PointerType::getUnqual(ctx); if (is_visitor) { // cf runtime/util/header.h visitChildren - auto *file = make_writer_type(ctx); - arg_types.push_back(file); + arg_types.push_back(ptr_ty); arg_types.push_back( make_packed_visitor_structure_type(ctx, module, is_serialize) ->getPointerTo()); if (!is_serialize) { - arg_types.push_back(llvm::PointerType::getUnqual(ctx)); + arg_types.push_back(ptr_ty); } } else { - arg_types.push_back(llvm::PointerType::getUnqual( - llvm::ArrayType::get(llvm::PointerType::getUnqual(ctx), 0))); + arg_types.push_back(ptr_ty); } auto *func = llvm::cast(get_or_insert_function( @@ -884,8 +774,7 @@ static void get_store( int idx = 0; auto *block_type = get_block_type(module, definition, symbol); auto *cast = new llvm::BitCastInst( - func->arg_begin(), llvm::PointerType::getUnqual(block_type), "", - case_block); + func->arg_begin(), llvm::PointerType::getUnqual(ctx), "", case_block); for (auto const &sort : symbol->get_arguments()) { value_type cat = dynamic_cast(sort.get()) ->get_category(definition); @@ -931,6 +820,7 @@ static void visit_collection( llvm::Value *state_ptr, bool use_sort_name) { llvm::LLVMContext &ctx = module->getContext(); llvm::Constant *zero = llvm::ConstantInt::get(llvm::Type::getInt64Ty(ctx), 0); + auto *ptr_ty = llvm::PointerType::getUnqual(ctx); auto indices = std::vector{zero, zero}; auto *sort_decl = definition->get_sort_declarations().at(composite_sort->get_name()); @@ -948,8 +838,7 @@ static void visit_collection( = get_symbol_name_ptr(concat_symbol, nullptr, module, use_sort_name); } else { if (use_sort_name) { - concat_ptr - = llvm::ConstantPointerNull::get(llvm::PointerType::getUnqual(ctx)); + concat_ptr = llvm::ConstantPointerNull::get(ptr_ty); } else { concat_ptr = llvm::ConstantInt::get(llvm::Type::getInt32Ty(ctx), 0); } @@ -974,17 +863,15 @@ static void visit_collection( element->get_constructor()->get_name() + "{}"); auto *element_ptr = get_symbol_name_ptr(element_symbol, nullptr, module, use_sort_name); - auto *file = make_writer_type(ctx); - auto *i8_ptr_ty = llvm::PointerType::getUnqual(ctx); llvm::Type *sort_type = nullptr; if (use_sort_name) { - sort_type = i8_ptr_ty; + sort_type = ptr_ty; } else { sort_type = llvm::Type::getInt32Ty(ctx); } auto *fn_type = llvm::FunctionType::get( llvm::Type::getVoidTy(ctx), - {file, child_ptr->getType(), sort_type, sort_type, sort_type, i8_ptr_ty}, + {ptr_ty, child_ptr->getType(), sort_type, sort_type, sort_type, ptr_ty}, false); llvm::CallInst::Create( fn_type, callback, @@ -1000,15 +887,13 @@ static void get_visitor( bool use_sort_name) { llvm::LLVMContext &ctx = module->getContext(); llvm::Constant *zero = llvm::ConstantInt::get(llvm::Type::getInt64Ty(ctx), 0); + auto *ptr_ty = llvm::PointerType::getUnqual(ctx); auto indices = std::vector{zero, zero}; llvm::Function *func = case_block->getParent(); int idx = 0; auto *block_type = get_block_type(module, definition, symbol); - auto *cast = new llvm::BitCastInst( - func->arg_begin(), llvm::PointerType::getUnqual(block_type), "", - case_block); + auto *cast = new llvm::BitCastInst(func->arg_begin(), ptr_ty, "", case_block); unsigned i = 0; - auto *file = make_writer_type(ctx); auto *state_ptr = func->arg_end() - 1; @@ -1036,7 +921,7 @@ static void get_visitor( } sort_val = llvm::ConstantExpr::getInBoundsGetElementPtr( str->getType(), global, indices); - sort_type = llvm::PointerType::getUnqual(ctx); + sort_type = ptr_ty; } else { uint32_t const num_tags = definition->get_symbols().size(); uint32_t ordinal @@ -1050,8 +935,8 @@ static void get_visitor( llvm::CallInst::Create( llvm::FunctionType::get( llvm::Type::getVoidTy(ctx), - {file, child->getType(), sort_type, llvm::Type::getInt1Ty(ctx), - llvm::PointerType::getUnqual(ctx)}, + {ptr_ty, child->getType(), sort_type, llvm::Type::getInt1Ty(ctx), + ptr_ty}, false), callbacks.at(0), {func->arg_begin() + 1, child, sort_val, @@ -1064,9 +949,7 @@ static void get_visitor( llvm::CallInst::Create( llvm::FunctionType::get( llvm::Type::getVoidTy(ctx), - {file, child->getType(), sort_type, - llvm::PointerType::getUnqual(ctx)}, - false), + {ptr_ty, child->getType(), sort_type, ptr_ty}, false), callbacks.at(4), {func->arg_begin() + 1, child, sort_val, state_ptr}, "", case_block); break; @@ -1074,9 +957,7 @@ static void get_visitor( llvm::CallInst::Create( llvm::FunctionType::get( llvm::Type::getVoidTy(ctx), - {file, child->getType(), sort_type, - llvm::PointerType::getUnqual(ctx)}, - false), + {ptr_ty, child->getType(), sort_type, ptr_ty}, false), callbacks.at(5), {func->arg_begin() + 1, child, sort_val, state_ptr}, "", case_block); break; @@ -1084,9 +965,7 @@ static void get_visitor( llvm::CallInst::Create( llvm::FunctionType::get( llvm::Type::getVoidTy(ctx), - {file, child->getType(), sort_type, - llvm::PointerType::getUnqual(ctx)}, - false), + {ptr_ty, child->getType(), sort_type, ptr_ty}, false), callbacks.at(6), {func->arg_begin() + 1, child, sort_val, state_ptr}, "", case_block); break; @@ -1094,9 +973,7 @@ static void get_visitor( llvm::CallInst::Create( llvm::FunctionType::get( llvm::Type::getVoidTy(ctx), - {file, child->getType(), sort_type, - llvm::PointerType::getUnqual(ctx)}, - false), + {ptr_ty, child->getType(), sort_type, ptr_ty}, false), callbacks.at(7), {func->arg_begin() + 1, child, sort_val, state_ptr}, "", case_block); break; @@ -1108,14 +985,12 @@ static void get_visitor( = llvm::ConstantInt::get(llvm::Type::getInt64Ty(ctx), cat.bits); auto *fn_type = llvm::FunctionType::get( llvm::Type::getVoidTy(ctx), - {file, llvm::PointerType::getUnqual(ctx), llvm::Type::getInt64Ty(ctx), - sort_type, llvm::PointerType::getUnqual(ctx)}, + {ptr_ty, ptr_ty, llvm::Type::getInt64Ty(ctx), sort_type, ptr_ty}, false); if (nwords == 0) { llvm::CallInst::Create( fn_type, func->arg_begin() + 10, - {func->arg_begin() + 1, - llvm::ConstantPointerNull::get(llvm::PointerType::getUnqual(ctx)), + {func->arg_begin() + 1, llvm::ConstantPointerNull::get(ptr_ty), nbits, sort_val, state_ptr}, "", case_block); } else { @@ -1184,8 +1059,7 @@ static void get_visitor( if (i != symbol->get_arguments().size() - 1 && use_sort_name) { llvm::CallInst::Create( llvm::FunctionType::get( - llvm::Type::getVoidTy(ctx), - {file, llvm::PointerType::getUnqual(ctx)}, false), + llvm::Type::getVoidTy(ctx), {ptr_ty, ptr_ty}, false), callbacks.at(9), {func->arg_begin() + 1, state_ptr}, "", case_block); } i++; @@ -1262,14 +1136,12 @@ static void emit_layouts(kore_definition *definition, llvm::Module *module) { layouts[entry.second->get_layout()] = entry.second; } llvm::LLVMContext &ctx = module->getContext(); + auto *ptr_ty = llvm::PointerType::getUnqual(ctx); std::vector arg_types; arg_types.push_back(llvm::Type::getInt16Ty(ctx)); auto *func = llvm::cast(get_or_insert_function( module, "get_layout_data", - llvm::FunctionType::get( - llvm::PointerType::getUnqual(llvm::StructType::getTypeByName( - module->getContext(), layout_struct)), - arg_types, false))); + llvm::FunctionType::get(ptr_ty, arg_types, false))); init_debug_function( "get_layout_data", "get_layout_data", get_debug_function_type( @@ -1281,10 +1153,7 @@ static void emit_layouts(kore_definition *definition, llvm::Module *module) { auto *stuck = llvm::BasicBlock::Create(ctx, "stuck"); auto *switch_inst = llvm::SwitchInst::Create( func->arg_begin(), stuck, layouts.size(), entry_block); - auto *phi = llvm::PHINode::Create( - llvm::PointerType::getUnqual( - llvm::StructType::getTypeByName(module->getContext(), layout_struct)), - layouts.size(), "phi", merge_block); + auto *phi = llvm::PHINode::Create(ptr_ty, layouts.size(), "phi", merge_block); for (auto entry : layouts) { uint16_t layout = entry.first; auto *symbol = entry.second; @@ -1369,8 +1238,7 @@ static void emit_sort_table_v2(kore_definition *def, llvm::Module *mod) { subtable_type, subtable_var, indices); }; - auto *i32_ty = llvm::Type::getInt32Ty(mod->getContext()); - auto *entry_ty = llvm::PointerType::getUnqual(i32_ty); + auto *entry_ty = llvm::PointerType::getUnqual(mod->getContext()); auto *debug_ty = get_pointer_debug_type(get_int_debug_type(), "int *"); emit_data_table_for_symbol( @@ -1382,8 +1250,9 @@ static void emit_sort_table(kore_definition *def, llvm::Module *mod) { kore_symbol *symbol) -> llvm::Constant * { auto &ctx = module->getContext(); - auto *subtable_type = llvm::ArrayType::get( - llvm::PointerType::getUnqual(ctx), symbol->get_arguments().size()); + auto *ptr_ty = llvm::PointerType::getUnqual(ctx); + auto *subtable_type + = llvm::ArrayType::get(ptr_ty, symbol->get_arguments().size()); auto *subtable = module->getOrInsertGlobal( fmt::format("sorts_{}", ast_to_string(*symbol)), subtable_type); auto *subtable_var = llvm::dyn_cast(subtable); @@ -1391,8 +1260,7 @@ static void emit_sort_table(kore_definition *def, llvm::Module *mod) { "sorts_" + symbol->get_name(), get_array_debug_type( get_char_ptr_debug_type(), symbol->get_arguments().size(), - llvm::DataLayout(module).getABITypeAlign( - llvm::PointerType::getUnqual(ctx))), + llvm::DataLayout(module).getABITypeAlign(ptr_ty)), subtable_var); llvm::Constant *zero = llvm::ConstantInt::get(llvm::Type::getInt64Ty(ctx), 0); @@ -1415,12 +1283,11 @@ static void emit_sort_table(kore_definition *def, llvm::Module *mod) { subtable_type, subtable_var, indices); }; - auto *i8_ptr_ty = llvm::PointerType::getUnqual(mod->getContext()); - auto *entry_ty = llvm::PointerType::getUnqual(i8_ptr_ty); + auto *ptr_ty = llvm::PointerType::getUnqual(mod->getContext()); auto *debug_ty = get_pointer_debug_type(get_char_ptr_debug_type(), "char **"); emit_data_table_for_symbol( - "get_argument_sorts_for_tag", entry_ty, debug_ty, def, mod, getter); + "get_argument_sorts_for_tag", ptr_ty, debug_ty, def, mod, getter); } /* diff --git a/lib/codegen/Util.cpp b/lib/codegen/Util.cpp index cb1fcbbcd..8f71b980a 100644 --- a/lib/codegen/Util.cpp +++ b/lib/codegen/Util.cpp @@ -24,24 +24,9 @@ llvm::Function *kore_heap_alloc(std::string const &name, llvm::Module *module) { } llvm::Instruction *create_malloc( - llvm::BasicBlock *block, llvm::Type *int_ptr_ty, llvm::Type *alloc_ty, - llvm::Value *alloc_size, llvm::Value *array_size, llvm::Function *malloc_f, - std::string const &name) { -#if LLVM_VERSION_MAJOR >= 18 - auto b = llvm::IRBuilder<>(block); - return b.CreateMalloc( - int_ptr_ty, alloc_ty, alloc_size, array_size, malloc_f, name); -#elif LLVM_VERSION_MAJOR >= 16 - auto *call = llvm::CallInst::CreateMalloc( - block, int_ptr_ty, alloc_ty, alloc_size, array_size, malloc_f, name); - call->insertInto(block, block->end()); - return call; -#else - auto *call = llvm::CallInst::CreateMalloc( - block, int_ptr_ty, alloc_ty, alloc_size, array_size, malloc_f, name); - call->insertAfter(&block->back()); - return call; -#endif + llvm::BasicBlock *block, llvm::Value *alloc_size, + llvm::Function *malloc_f) { + return llvm::CallInst::Create(malloc_f, {alloc_size}, "", block); } llvm::Constant *get_offset_of_member( diff --git a/runtime/finish_rewriting.ll b/runtime/finish_rewriting.ll index 779d8d175..fd3423304 100644 --- a/runtime/finish_rewriting.ll +++ b/runtime/finish_rewriting.ll @@ -2,21 +2,21 @@ target datalayout = "@BACKEND_TARGET_DATALAYOUT@" target triple = "@BACKEND_TARGET_TRIPLE@" %blockheader = type { i64 } -%block = type { %blockheader, [0 x i64 *] } ; 16-bit layout, 8-bit length, 32-bit tag, children -%mpz = type { i32, i32, i64* } +%block = type { %blockheader, [0 x ptr] } ; 16-bit layout, 8-bit length, 32-bit tag, children +%mpz = type { i32, i32, ptr } -declare i64 @__gmpz_get_ui(%mpz*) +declare i64 @__gmpz_get_ui(ptr) -@exit_int_0 = global %mpz { i32 0, i32 0, i64* getelementptr inbounds ([0 x i64], [0 x i64]* @exit_int_0_limbs, i32 0, i32 0) } +@exit_int_0 = global %mpz { i32 0, i32 0, ptr getelementptr inbounds ([0 x i64], ptr @exit_int_0_limbs, i32 0, i32 0) } @exit_int_0_limbs = global [0 x i64] zeroinitializer -define weak tailcc %mpz* @"eval_LblgetExitCode{SortGeneratedTopCell{}}"(%block*) { - ret %mpz* @exit_int_0 +define weak tailcc ptr @"eval_LblgetExitCode{SortGeneratedTopCell{}}"(ptr) { + ret ptr @exit_int_0 } -define i32 @get_exit_code(%block* %subject) { - %exit_z = call tailcc %mpz* @"eval_LblgetExitCode{SortGeneratedTopCell{}}"(%block* %subject) - %exit_ul = call i64 @__gmpz_get_ui(%mpz* %exit_z) +define i32 @get_exit_code(ptr %subject) { + %exit_z = call tailcc ptr @"eval_LblgetExitCode{SortGeneratedTopCell{}}"(ptr %subject) + %exit_ul = call i64 @__gmpz_get_ui(ptr %exit_z) %exit_trunc = trunc i64 %exit_ul to i32 ret i32 %exit_trunc } diff --git a/runtime/fresh.ll b/runtime/fresh.ll index 0dc848cbe..110291caa 100644 --- a/runtime/fresh.ll +++ b/runtime/fresh.ll @@ -3,39 +3,37 @@ target triple = "@BACKEND_TARGET_TRIPLE@" %string = type { %blockheader, [0 x i8] } ; 10-bit layout, 4-bit gc flags, 10 unused bits, 40-bit length (or buffer capacity for string pointed by stringbuffers), bytes %blockheader = type { i64 } -%block = type { %blockheader, [0 x i64 *] } ; 16-bit layout, 8-bit length, 32-bit tag, children -%mpz = type { i32, i32, i64* } +%block = type { %blockheader, [0 x ptr] } ; 16-bit layout, 8-bit length, 32-bit tag, children +%mpz = type { i32, i32, ptr } declare void @abort() #0 -define weak tailcc %block* @"eval_LblgetGeneratedCounterCell{SortGeneratedTopCell{}}"(%block*) { +define weak tailcc ptr @"eval_LblgetGeneratedCounterCell{SortGeneratedTopCell{}}"(ptr) { call void @abort() unreachable } -declare i32 @get_tag_for_fresh_sort(i8*) -declare %mpz* @hook_INT_add(%mpz*, %mpz*) -declare i8* @evaluate_function_symbol(i32, i8**) -declare i8* @get_terminated_string(%string*) +declare i32 @get_tag_for_fresh_sort(ptr) +declare ptr @hook_INT_add(ptr, ptr) +declare ptr @evaluate_function_symbol(i32, ptr) +declare ptr @get_terminated_string(ptr) -@fresh_int_1 = global %mpz { i32 1, i32 1, i64* getelementptr inbounds ([1 x i64], [1 x i64]* @fresh_int_1_limbs, i32 0, i32 0) } +@fresh_int_1 = global %mpz { i32 1, i32 1, ptr getelementptr inbounds ([1 x i64], ptr @fresh_int_1_limbs, i32 0, i32 0) } @fresh_int_1_limbs = global [1 x i64] [i64 1] -define i8* @get_fresh_constant(%string* %sort, %block* %top) { +define ptr @get_fresh_constant(ptr %sort, ptr %top) { entry: - %counterCell = call tailcc %block* @"eval_LblgetGeneratedCounterCell{SortGeneratedTopCell{}}"(%block* %top) - %counterCellPointer = getelementptr %block, %block* %counterCell, i64 0, i32 1, i64 0 - %mpzPtrPtr = bitcast i64** %counterCellPointer to %mpz** - %currCounter = load %mpz*, %mpz** %mpzPtrPtr - %nextCounter = call %mpz* @hook_INT_add(%mpz* %currCounter, %mpz* @fresh_int_1) - store %mpz* %nextCounter, %mpz** %mpzPtrPtr - %sortData = call i8* @get_terminated_string(%string* %sort) - %tag = call i32 @get_tag_for_fresh_sort(i8* %sortData) - %args = alloca i8* - %voidPtr = bitcast %mpz* %currCounter to i8* - store i8* %voidPtr, i8** %args - %retval = call i8* @evaluate_function_symbol(i32 %tag, i8** %args) - ret i8* %retval + %counterCell = call tailcc ptr @"eval_LblgetGeneratedCounterCell{SortGeneratedTopCell{}}"(ptr %top) + %counterCellPointer = getelementptr %block, ptr %counterCell, i64 0, i32 1, i64 0 + %currCounter = load ptr, ptr %counterCellPointer + %nextCounter = call ptr @hook_INT_add(ptr %currCounter, ptr @fresh_int_1) + store ptr %nextCounter, ptr %counterCellPointer + %sortData = call ptr @get_terminated_string(ptr %sort) + %tag = call i32 @get_tag_for_fresh_sort(ptr %sortData) + %args = alloca ptr + store ptr %currCounter, ptr %args + %retval = call ptr @evaluate_function_symbol(i32 %tag, ptr %args) + ret ptr %retval } attributes #0 = { noreturn } diff --git a/runtime/getTag.ll b/runtime/getTag.ll index 3baff80dc..bf053328e 100644 --- a/runtime/getTag.ll +++ b/runtime/getTag.ll @@ -2,18 +2,18 @@ target datalayout = "@BACKEND_TARGET_DATALAYOUT@" target triple = "@BACKEND_TARGET_TRIPLE@" %blockheader = type { i64 } -%block = type { %blockheader, [0 x i64 *] } ; 16-bit layout, 8-bit length, 32-bit tag, children +%block = type { %blockheader, [0 x ptr] } ; 16-bit layout, 8-bit length, 32-bit tag, children -define i32 @get_tag(%block* %arg) { - %intptr = ptrtoint %block* %arg to i64 +define i32 @get_tag(ptr %arg) { + %intptr = ptrtoint ptr %arg to i64 %isConstant = trunc i64 %intptr to i1 br i1 %isConstant, label %constant, label %block constant: %taglong = lshr i64 %intptr, 32 br label %exit block: - %hdrptr = getelementptr inbounds %block, %block* %arg, i64 0, i32 0, i32 0 - %hdr = load i64, i64* %hdrptr + %hdrptr = getelementptr inbounds %block, ptr %arg, i64 0, i32 0, i32 0 + %hdr = load i64, ptr %hdrptr %layout = lshr i64 %hdr, @LAYOUT_OFFSET@ %isstring = icmp eq i64 %layout, 0 %tagorstring = select i1 %isstring, i64 -1, i64 %hdr diff --git a/runtime/main/main.ll b/runtime/main/main.ll index df83bd116..5e0595b06 100644 --- a/runtime/main/main.ll +++ b/runtime/main/main.ll @@ -2,34 +2,34 @@ target datalayout = "@BACKEND_TARGET_DATALAYOUT@" target triple = "@BACKEND_TARGET_TRIPLE@" %blockheader = type { i64 } -%block = type { %blockheader, [0 x i64 *] } ; 16-bit layout, 8-bit length, 32-bit tag, children +%block = type { %blockheader, [0 x ptr] } ; 16-bit layout, 8-bit length, 32-bit tag, children -declare %block* @parse_configuration(i8*) -declare i64 @atol(i8*) -declare i8* @fopen(i8*, i8*) +declare ptr @parse_configuration(ptr) +declare i64 @atol(ptr) +declare ptr @fopen(ptr, ptr) -declare %block* @take_steps(i64, %block*) -declare void @finish_rewriting(%block*, i1) #0 +declare ptr @take_steps(i64, ptr) +declare void @finish_rewriting(ptr, i1) #0 declare void @init_static_objects() -declare void @print_proof_hint_header(i8*) +declare void @print_proof_hint_header(ptr) @statistics.flag = private constant [13 x i8] c"--statistics\00" @binary_out.flag = private constant [16 x i8] c"--binary-output\00" @proof_out.flag = private constant [15 x i8] c"--proof-output\00" -@output_file = external global i8* +@output_file = external global ptr @a_str = private constant [2 x i8] c"a\00" @statistics = external global i1 @binary_output = external global i1 @proof_output = external global i1 -declare i32 @strcmp(i8* %a, i8* %b) +declare i32 @strcmp(ptr %a, ptr %b) -define void @parse_flags(i32 %argc, i8** %argv) { +define void @parse_flags(i32 %argc, ptr %argv) { entry: - store i1 0, i1* @statistics + store i1 0, ptr @statistics br label %header header: @@ -38,35 +38,35 @@ header: br i1 %continue, label %body, label %exit body: - %argv.idx = getelementptr inbounds i8*, i8** %argv, i32 %idx - %arg = load i8*, i8** %argv.idx + %argv.idx = getelementptr inbounds ptr, ptr %argv, i32 %idx + %arg = load ptr, ptr %argv.idx br label %body.stats body.stats: - %stats.cmp = call i32 @strcmp(i8* %arg, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @statistics.flag, i64 0, i64 0)) + %stats.cmp = call i32 @strcmp(ptr %arg, ptr getelementptr inbounds ([13 x i8], ptr @statistics.flag, i64 0, i64 0)) %stats.eq = icmp eq i32 %stats.cmp, 0 br i1 %stats.eq, label %set.stats, label %binary.body set.stats: - store i1 1, i1* @statistics + store i1 1, ptr @statistics br label %binary.body binary.body: - %binary.cmp = call i32 @strcmp(i8* %arg, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @binary_out.flag, i64 0, i64 0)) + %binary.cmp = call i32 @strcmp(ptr %arg, ptr getelementptr inbounds ([16 x i8], ptr @binary_out.flag, i64 0, i64 0)) %binary.eq = icmp eq i32 %binary.cmp, 0 br i1 %binary.eq, label %binary.set, label %proof.body binary.set: - store i1 1, i1* @binary_output + store i1 1, ptr @binary_output br label %proof.body proof.body: - %proof.cmp = call i32 @strcmp(i8* %arg, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @proof_out.flag, i64 0, i64 0)) + %proof.cmp = call i32 @strcmp(ptr %arg, ptr getelementptr inbounds ([15 x i8], ptr @proof_out.flag, i64 0, i64 0)) %proof.eq = icmp eq i32 %proof.cmp, 0 br i1 %proof.eq, label %proof.set, label %body.tail proof.set: - store i1 1, i1* @proof_output + store i1 1, ptr @proof_output br label %body.tail body.tail: @@ -80,31 +80,31 @@ exit: ret void } -define i32 @main(i32 %argc, i8** %argv) { +define i32 @main(i32 %argc, ptr %argv) { entry: - %filename_ptr = getelementptr inbounds i8*, i8** %argv, i64 1 - %filename = load i8*, i8** %filename_ptr - %depth_ptr = getelementptr inbounds i8*, i8** %argv, i64 2 - %depth_str = load i8*, i8** %depth_ptr - %depth = call i64 @atol(i8* %depth_str) - %output_ptr = getelementptr inbounds i8*, i8** %argv, i64 3 - %output_str = load i8*, i8** %output_ptr - %output_file = call i8* @fopen(i8* %output_str, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @a_str, i64 0, i64 0)) - store i8* %output_file, i8** @output_file + %filename_ptr = getelementptr inbounds ptr, ptr %argv, i64 1 + %filename = load ptr, ptr %filename_ptr + %depth_ptr = getelementptr inbounds ptr, ptr %argv, i64 2 + %depth_str = load ptr, ptr %depth_ptr + %depth = call i64 @atol(ptr %depth_str) + %output_ptr = getelementptr inbounds ptr, ptr %argv, i64 3 + %output_str = load ptr, ptr %output_ptr + %output_file = call ptr @fopen(ptr %output_str, ptr getelementptr inbounds ([2 x i8], ptr @a_str, i64 0, i64 0)) + store ptr %output_file, ptr @output_file - call void @parse_flags(i32 %argc, i8** %argv) + call void @parse_flags(i32 %argc, ptr %argv) call void @init_static_objects() - %proof_output = load i1, i1* @proof_output + %proof_output = load i1, ptr @proof_output br i1 %proof_output, label %if, label %else if: - call void @print_proof_hint_header(i8* %output_file) + call void @print_proof_hint_header(ptr %output_file) br label %else else: - %ret = call %block* @parse_configuration(i8* %filename) - %result = call %block* @take_steps(i64 %depth, %block* %ret) - call void @finish_rewriting(%block* %result, i1 0) + %ret = call ptr @parse_configuration(ptr %filename) + %result = call ptr @take_steps(i64 %depth, ptr %ret) + call void @finish_rewriting(ptr %result, i1 0) unreachable } diff --git a/runtime/move_float.ll b/runtime/move_float.ll index 2c4b6e46d..d66b7b217 100644 --- a/runtime/move_float.ll +++ b/runtime/move_float.ll @@ -2,17 +2,16 @@ target datalayout = "@BACKEND_TARGET_DATALAYOUT@" target triple = "@BACKEND_TARGET_TRIPLE@" %blockheader = type { i64 } -%floating = type { i64, { i64, i32, i64, i64 * } } ; exp, mpfr_t +%floating = type { i64, { i64, i32, i64, ptr } } ; exp, mpfr_t ; helper function for float hooks -define %floating* @move_float(%floating* %val) { - %loaded = load %floating, %floating* %val - %malloccall = tail call i8* @kore_alloc_floating(i64 0) - %ptr = bitcast i8* %malloccall to %floating* - store %floating %loaded, %floating* %ptr - ret %floating* %ptr +define ptr @move_float(ptr %val) { + %loaded = load %floating, ptr %val + %malloccall = tail call ptr @kore_alloc_floating(i64 0) + store %floating %loaded, ptr %malloccall + ret ptr %malloccall } -declare noalias i8* @kore_alloc_floating(i64) +declare noalias ptr @kore_alloc_floating(i64) diff --git a/runtime/move_int.ll b/runtime/move_int.ll index d0849ef66..d63a1eb54 100644 --- a/runtime/move_int.ll +++ b/runtime/move_int.ll @@ -1,16 +1,15 @@ target datalayout = "@BACKEND_TARGET_DATALAYOUT@" target triple = "@BACKEND_TARGET_TRIPLE@" -%mpz = type { i32, i32, i64 * } ; mpz_t +%mpz = type { i32, i32, ptr } ; mpz_t ; helper function for int hooks -define %mpz* @move_int(%mpz* %val) { - %loaded = load %mpz, %mpz* %val - %malloccall = tail call i8* @kore_alloc_integer(i64 0) - %ptr = bitcast i8* %malloccall to %mpz* - store %mpz %loaded, %mpz* %ptr - ret %mpz* %ptr +define ptr @move_int(ptr %val) { + %loaded = load %mpz, ptr %val + %malloccall = tail call ptr @kore_alloc_integer(i64 0) + store %mpz %loaded, ptr %malloccall + ret ptr %malloccall } -declare noalias i8* @kore_alloc_integer(i64) +declare noalias ptr @kore_alloc_integer(i64) diff --git a/runtime/string_equal.ll b/runtime/string_equal.ll index 6d89bb912..6033bdebf 100644 --- a/runtime/string_equal.ll +++ b/runtime/string_equal.ll @@ -1,13 +1,13 @@ target datalayout = "@BACKEND_TARGET_DATALAYOUT@" target triple = "@BACKEND_TARGET_TRIPLE@" -declare i32 @memcmp(i8*, i8*, i64); +declare i32 @memcmp(ptr, ptr, i64); -define i1 @string_equal(i8* %str1, i8* %str2, i64 %len1, i64 %len2) { +define i1 @string_equal(ptr %str1, ptr %str2, i64 %len1, i64 %len2) { %len_eq = icmp eq i64 %len1, %len2 %len_lt = icmp ult i64 %len1, %len2 %min_len = select i1 %len_lt, i64 %len1, i64 %len2 - %result = call i32 @memcmp(i8* %str1, i8* %str2, i64 %min_len) + %result = call i32 @memcmp(ptr %str1, ptr %str2, i64 %min_len) %prefix_eq = icmp eq i32 %result, 0 %retval = and i1 %len_eq, %prefix_eq ret i1 %retval diff --git a/runtime/take_steps.ll b/runtime/take_steps.ll index fb5cdffd2..89236068a 100644 --- a/runtime/take_steps.ll +++ b/runtime/take_steps.ll @@ -2,71 +2,71 @@ target datalayout = "@BACKEND_TARGET_DATALAYOUT@" target triple = "@BACKEND_TARGET_TRIPLE@" %blockheader = type { i64 } -%block = type { %blockheader, [0 x i64 *] } ; 16-bit layout, 8-bit length, 32-bit tag, children +%block = type { %blockheader, [0 x ptr] } ; 16-bit layout, 8-bit length, 32-bit tag, children -declare tailcc %block* @k_step(%block*) -declare tailcc %block** @step_all(%block*, i64*) -declare void @serialize_configuration_to_file_v2(i8*, %block*) -declare void @write_uint64_to_file(i8*, i64) +declare tailcc ptr @k_step(ptr) +declare tailcc void @step_all(ptr) +declare void @serialize_configuration_to_file_v2(ptr, ptr) +declare void @write_uint64_to_file(ptr, i64) @proof_output = external global i1 -@output_file = external global i8* +@output_file = external global ptr @depth = thread_local global i64 zeroinitializer @steps = thread_local global i64 zeroinitializer @current_interval = thread_local global i64 0 @GC_THRESHOLD = thread_local global i64 @GC_THRESHOLD@ -@gc_roots = global [256 x i8 *] zeroinitializer +@gc_roots = global [256 x ptr] zeroinitializer define void @set_gc_threshold(i64 %threshold) { - store i64 %threshold, i64* @GC_THRESHOLD + store i64 %threshold, ptr @GC_THRESHOLD ret void } define i64 @get_gc_threshold() { - %threshold = load i64, i64* @GC_THRESHOLD + %threshold = load i64, ptr @GC_THRESHOLD ret i64 %threshold } define i1 @finished_rewriting() { entry: - %depth = load i64, i64* @depth + %depth = load i64, ptr @depth %hasDepth = icmp sge i64 %depth, 0 - %steps = load i64, i64* @steps + %steps = load i64, ptr @steps %stepsPlusOne = add i64 %steps, 1 - store i64 %stepsPlusOne, i64* @steps + store i64 %stepsPlusOne, ptr @steps br i1 %hasDepth, label %if, label %else if: %depthMinusOne = sub i64 %depth, 1 - store i64 %depthMinusOne, i64* @depth + store i64 %depthMinusOne, ptr @depth %finished = icmp eq i64 %depth, 0 ret i1 %finished else: ret i1 false } -define %block* @take_steps(i64 %depth, %block* %subject) { - %proof_output = load i1, i1* @proof_output +define ptr @take_steps(i64 %depth, ptr %subject) { + %proof_output = load i1, ptr @proof_output br i1 %proof_output, label %if, label %merge if: - %output_file = load i8*, i8** @output_file - call void @write_uint64_to_file(i8* %output_file, i64 18446744073709551615) - call void @serialize_configuration_to_file_v2(i8* %output_file, %block* %subject) + %output_file = load ptr, ptr @output_file + call void @write_uint64_to_file(ptr %output_file, i64 18446744073709551615) + call void @serialize_configuration_to_file_v2(ptr %output_file, ptr %subject) br label %merge merge: - store i64 %depth, i64* @depth - %result = call tailcc %block* @k_step(%block* %subject) - ret %block* %result + store i64 %depth, ptr @depth + %result = call tailcc ptr @k_step(ptr %subject) + ret ptr %result } -define %block** @take_search_step(%block* %subject, i64* %count) { - store i64 -1, i64* @depth - %result = call tailcc %block** @step_all(%block* %subject, i64* %count) - ret %block** %result +define void @take_search_step(ptr %subject) { + store i64 -1, ptr @depth + call tailcc void @step_all(ptr %subject) + ret void } define i64 @get_steps() { entry: - %steps = load i64, i64* @steps + %steps = load i64, ptr @steps ret i64 %steps }