diff options
| author | gingerBill <bill@gingerbill.org> | 2023-03-16 15:16:17 +0000 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2023-03-16 15:16:17 +0000 |
| commit | 8dc70f797cf8b4315d689ce94ab004faadb015b7 (patch) | |
| tree | 5429d9d7aa8a6071761b993de0a25ff6be0c84e7 /src/llvm_backend.cpp | |
| parent | 2cf8a9da6f7becfe7c8d279af4cc81b02dd706b6 (diff) | |
Increase use of `temporary_allocator()` where possible
Diffstat (limited to 'src/llvm_backend.cpp')
| -rw-r--r-- | src/llvm_backend.cpp | 63 |
1 files changed, 42 insertions, 21 deletions
diff --git a/src/llvm_backend.cpp b/src/llvm_backend.cpp index 543f5d833..d8ff01554 100644 --- a/src/llvm_backend.cpp +++ b/src/llvm_backend.cpp @@ -96,10 +96,12 @@ gb_internal void lb_set_entity_from_other_modules_linkage_correctly(lbModule *ot } gb_internal void lb_emit_init_context(lbProcedure *p, lbAddr addr) { + TEMPORARY_ALLOCATOR_GUARD(); + GB_ASSERT(addr.kind == lbAddr_Context); GB_ASSERT(addr.ctx.sel.index.count == 0); - auto args = array_make<lbValue>(permanent_allocator(), 1); + auto args = array_make<lbValue>(temporary_allocator(), 1); args[0] = addr.addr; lb_emit_runtime_call(p, "__init_context", args); } @@ -279,9 +281,11 @@ gb_internal lbValue lb_equal_proc_for_type(lbModule *m, Type *type) { } gb_internal lbValue lb_simple_compare_hash(lbProcedure *p, Type *type, lbValue data, lbValue seed) { + TEMPORARY_ALLOCATOR_GUARD(); + GB_ASSERT_MSG(is_type_simple_compare(type), "%s", type_to_string(type)); - auto args = array_make<lbValue>(permanent_allocator(), 3); + auto args = array_make<lbValue>(temporary_allocator(), 3); args[0] = data; args[1] = seed; args[2] = lb_const_int(p->module, t_int, type_size_of(type)); @@ -334,11 +338,13 @@ gb_internal lbValue lb_hasher_proc_for_type(lbModule *m, Type *type) { return {p->value, p->type}; } + TEMPORARY_ALLOCATOR_GUARD(); + if (type->kind == Type_Struct) { type_set_offsets(type); data = lb_emit_conv(p, data, t_u8_ptr); - auto args = array_make<lbValue>(permanent_allocator(), 2); + auto args = array_make<lbValue>(temporary_allocator(), 2); for_array(i, type->Struct.fields) { GB_ASSERT(type->Struct.offsets != nullptr); i64 offset = type->Struct.offsets[i]; @@ -352,7 +358,7 @@ gb_internal lbValue lb_hasher_proc_for_type(lbModule *m, Type *type) { } LLVMBuildRet(p->builder, seed.value); } else if (type->kind == Type_Union) { - auto args = array_make<lbValue>(permanent_allocator(), 2); + auto args = array_make<lbValue>(temporary_allocator(), 2); if (is_type_union_maybe_pointer(type)) { Type *v = type->Union.variants[0]; @@ -396,7 +402,7 @@ gb_internal lbValue lb_hasher_proc_for_type(lbModule *m, Type *type) { lbAddr pres = lb_add_local_generated(p, t_uintptr, false); lb_addr_store(p, pres, seed); - auto args = array_make<lbValue>(permanent_allocator(), 2); + auto args = array_make<lbValue>(temporary_allocator(), 2); lbValue elem_hasher = lb_hasher_proc_for_type(m, type->Array.elem); auto loop_data = lb_loop_start(p, cast(isize)type->Array.count, t_i32); @@ -417,7 +423,7 @@ gb_internal lbValue lb_hasher_proc_for_type(lbModule *m, Type *type) { lbAddr res = lb_add_local_generated(p, t_uintptr, false); lb_addr_store(p, res, seed); - auto args = array_make<lbValue>(permanent_allocator(), 2); + auto args = array_make<lbValue>(temporary_allocator(), 2); lbValue elem_hasher = lb_hasher_proc_for_type(m, type->EnumeratedArray.elem); auto loop_data = lb_loop_start(p, cast(isize)type->EnumeratedArray.count, t_i32); @@ -435,14 +441,14 @@ gb_internal lbValue lb_hasher_proc_for_type(lbModule *m, Type *type) { lbValue vres = lb_addr_load(p, res); LLVMBuildRet(p->builder, vres.value); } else if (is_type_cstring(type)) { - auto args = array_make<lbValue>(permanent_allocator(), 2); + auto args = array_make<lbValue>(temporary_allocator(), 2); args[0] = data; args[1] = seed; lbValue res = lb_emit_runtime_call(p, "default_hasher_cstring", args); lb_add_callsite_force_inline(p, res); LLVMBuildRet(p->builder, res.value); } else if (is_type_string(type)) { - auto args = array_make<lbValue>(permanent_allocator(), 2); + auto args = array_make<lbValue>(temporary_allocator(), 2); args[0] = data; args[1] = seed; lbValue res = lb_emit_runtime_call(p, "default_hasher_string", args); @@ -527,7 +533,8 @@ gb_internal lbValue lb_map_get_proc_for_type(lbModule *m, Type *type) { lbValue mask = lb_emit_conv(p, lb_emit_arith(p, Token_Sub, capacity, lb_const_int(m, t_int, 1), t_int), t_uintptr); { - auto args = array_make<lbValue>(heap_allocator(), 2); + TEMPORARY_ALLOCATOR_GUARD(); + auto args = array_make<lbValue>(temporary_allocator(), 2); args[0] = map; args[1] = h; lb_addr_store(p, pos, lb_emit_runtime_call(p, "map_desired_position", args)); @@ -554,7 +561,8 @@ gb_internal lbValue lb_map_get_proc_for_type(lbModule *m, Type *type) { lb_start_block(p, probe_block); { - auto args = array_make<lbValue>(heap_allocator(), 3); + TEMPORARY_ALLOCATOR_GUARD(); + auto args = array_make<lbValue>(temporary_allocator(), 3); args[0] = map; args[1] = element_hash; args[2] = lb_addr_load(p, pos); @@ -612,6 +620,8 @@ gb_internal lbValue lb_map_get_proc_for_type(lbModule *m, Type *type) { // } gb_internal lbValue lb_map_set_proc_for_type(lbModule *m, Type *type) { + TEMPORARY_ALLOCATOR_GUARD(); + GB_ASSERT(!build_context.dynamic_map_calls); type = base_type(type); GB_ASSERT(type->kind == Type_Map); @@ -673,7 +683,7 @@ gb_internal lbValue lb_map_set_proc_for_type(lbModule *m, Type *type) { { lbValue map_get_proc = lb_map_get_proc_for_type(m, type); - auto args = array_make<lbValue>(permanent_allocator(), 3); + auto args = array_make<lbValue>(temporary_allocator(), 3); args[0] = lb_emit_conv(p, map_ptr, t_rawptr); args[1] = hash; args[2] = key_ptr; @@ -699,7 +709,7 @@ gb_internal lbValue lb_map_set_proc_for_type(lbModule *m, Type *type) { lbValue map_info = lb_gen_map_info_ptr(p->module, type); { - auto args = array_make<lbValue>(permanent_allocator(), 3); + auto args = array_make<lbValue>(temporary_allocator(), 3); args[0] = lb_emit_conv(p, map_ptr, t_rawptr); args[1] = map_info; args[2] = lb_emit_load(p, location_ptr); @@ -713,7 +723,7 @@ gb_internal lbValue lb_map_set_proc_for_type(lbModule *m, Type *type) { lb_start_block(p, insert_block); { - auto args = array_make<lbValue>(permanent_allocator(), 5); + auto args = array_make<lbValue>(temporary_allocator(), 5); args[0] = lb_emit_conv(p, map_ptr, t_rawptr); args[1] = map_info; args[2] = hash; @@ -883,6 +893,8 @@ gb_internal lbValue lb_const_hash(lbModule *m, lbValue key, Type *key_type) { } gb_internal lbValue lb_gen_map_key_hash(lbProcedure *p, lbValue key, Type *key_type, lbValue *key_ptr_) { + TEMPORARY_ALLOCATOR_GUARD(); + lbValue key_ptr = lb_address_from_load_or_generate_local(p, key); key_ptr = lb_emit_conv(p, key_ptr, t_rawptr); @@ -892,7 +904,7 @@ gb_internal lbValue lb_gen_map_key_hash(lbProcedure *p, lbValue key, Type *key_t if (hashed_key.value == nullptr) { lbValue hasher = lb_hasher_proc_for_type(p->module, key_type); - auto args = array_make<lbValue>(permanent_allocator(), 2); + auto args = array_make<lbValue>(temporary_allocator(), 2); args[0] = key_ptr; args[1] = lb_const_int(p->module, t_uintptr, 0); hashed_key = lb_emit_call(p, hasher, args); @@ -902,6 +914,8 @@ gb_internal lbValue lb_gen_map_key_hash(lbProcedure *p, lbValue key, Type *key_t } gb_internal lbValue lb_internal_dynamic_map_get_ptr(lbProcedure *p, lbValue const &map_ptr, lbValue const &key) { + TEMPORARY_ALLOCATOR_GUARD(); + Type *map_type = base_type(type_deref(map_ptr.type)); GB_ASSERT(map_type->kind == Type_Map); @@ -910,7 +924,7 @@ gb_internal lbValue lb_internal_dynamic_map_get_ptr(lbProcedure *p, lbValue cons lbValue hash = lb_gen_map_key_hash(p, key, map_type->Map.key, &key_ptr); if (build_context.dynamic_map_calls) { - auto args = array_make<lbValue>(permanent_allocator(), 4); + auto args = array_make<lbValue>(temporary_allocator(), 4); args[0] = lb_emit_transmute(p, map_ptr, t_raw_map_ptr); args[1] = lb_gen_map_info_ptr(p->module, map_type); args[2] = hash; @@ -920,7 +934,7 @@ gb_internal lbValue lb_internal_dynamic_map_get_ptr(lbProcedure *p, lbValue cons } else { lbValue map_get_proc = lb_map_get_proc_for_type(p->module, map_type); - auto args = array_make<lbValue>(permanent_allocator(), 3); + auto args = array_make<lbValue>(temporary_allocator(), 3); args[0] = lb_emit_conv(p, map_ptr, t_rawptr); args[1] = hash; args[2] = key_ptr; @@ -932,6 +946,8 @@ gb_internal lbValue lb_internal_dynamic_map_get_ptr(lbProcedure *p, lbValue cons gb_internal void lb_internal_dynamic_map_set(lbProcedure *p, lbValue const &map_ptr, Type *map_type, lbValue const &map_key, lbValue const &map_value, Ast *node) { + TEMPORARY_ALLOCATOR_GUARD(); + map_type = base_type(map_type); GB_ASSERT(map_type->kind == Type_Map); @@ -942,7 +958,7 @@ gb_internal void lb_internal_dynamic_map_set(lbProcedure *p, lbValue const &map_ lbValue value_ptr = lb_address_from_load_or_generate_local(p, v); if (build_context.dynamic_map_calls) { - auto args = array_make<lbValue>(permanent_allocator(), 6); + auto args = array_make<lbValue>(temporary_allocator(), 6); args[0] = lb_emit_conv(p, map_ptr, t_raw_map_ptr); args[1] = lb_gen_map_info_ptr(p->module, map_type); args[2] = hash; @@ -953,7 +969,7 @@ gb_internal void lb_internal_dynamic_map_set(lbProcedure *p, lbValue const &map_ } else { lbValue map_set_proc = lb_map_set_proc_for_type(p->module, map_type); - auto args = array_make<lbValue>(permanent_allocator(), 5); + auto args = array_make<lbValue>(temporary_allocator(), 5); args[0] = lb_emit_conv(p, map_ptr, t_rawptr); args[1] = hash; args[2] = lb_emit_conv(p, key_ptr, t_rawptr); @@ -967,12 +983,14 @@ gb_internal void lb_internal_dynamic_map_set(lbProcedure *p, lbValue const &map_ gb_internal lbValue lb_dynamic_map_reserve(lbProcedure *p, lbValue const &map_ptr, isize const capacity, TokenPos const &pos) { GB_ASSERT(!build_context.no_dynamic_literals); + TEMPORARY_ALLOCATOR_GUARD(); + String proc_name = {}; if (p->entity) { proc_name = p->entity->token.string; } - auto args = array_make<lbValue>(permanent_allocator(), 4); + auto args = array_make<lbValue>(temporary_allocator(), 4); args[0] = lb_emit_conv(p, map_ptr, t_rawptr); args[1] = lb_gen_map_info_ptr(p->module, type_deref(map_ptr.type)); args[2] = lb_const_int(p->module, t_uint, capacity); @@ -1032,7 +1050,9 @@ gb_internal void lb_finalize_objc_names(lbProcedure *p) { } lbModule *m = p->module; - auto args = array_make<lbValue>(permanent_allocator(), 1); + TEMPORARY_ALLOCATOR_GUARD(); + + auto args = array_make<lbValue>(temporary_allocator(), 1); LLVMSetLinkage(p->value, LLVMInternalLinkage); lb_begin_procedure_body(p); @@ -1811,7 +1831,8 @@ gb_internal lbProcedure *lb_create_main_procedure(lbModule *m, lbProcedure *star lbValue runner = lb_find_package_value(m, str_lit("testing"), str_lit("runner")); - auto args = array_make<lbValue>(permanent_allocator(), 1); + TEMPORARY_ALLOCATOR_GUARD(); + auto args = array_make<lbValue>(temporary_allocator(), 1); args[0] = lb_addr_load(p, all_tests_slice); lb_emit_call(p, runner, args); } else { |