diff options
| author | gingerBill <bill@gingerbill.org> | 2024-08-18 18:37:40 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2024-08-18 18:37:40 +0100 |
| commit | 8e52a525804244a7b45858ec4e8971ee55d34056 (patch) | |
| tree | a2aea2666493536691bc69c106a9dbf327a4e42d /src | |
| parent | f49ebae9562257effe014e3c175496915041d5f2 (diff) | |
Cache the paddding filler type
Diffstat (limited to 'src')
| -rw-r--r-- | src/llvm_backend.hpp | 9 | ||||
| -rw-r--r-- | src/llvm_backend_general.cpp | 3 | ||||
| -rw-r--r-- | src/llvm_backend_utility.cpp | 27 |
3 files changed, 36 insertions, 3 deletions
diff --git a/src/llvm_backend.hpp b/src/llvm_backend.hpp index 02daecf6b..29d2ccfe6 100644 --- a/src/llvm_backend.hpp +++ b/src/llvm_backend.hpp @@ -137,6 +137,12 @@ enum lbFunctionPassManagerKind { lbFunctionPassManager_COUNT }; +struct lbPadType { + i64 padding; + i64 padding_align; + LLVMTypeRef type; +}; + struct lbModule { LLVMModuleRef mod; LLVMContextRef ctx; @@ -199,6 +205,9 @@ struct lbModule { PtrMap<Ast *, lbAddr> exact_value_compound_literal_addr_map; // Key: Ast_CompoundLit LLVMPassManagerRef function_pass_managers[lbFunctionPassManager_COUNT]; + + BlockingMutex pad_types_mutex; + Array<lbPadType> pad_types; }; struct lbEntityCorrection { diff --git a/src/llvm_backend_general.cpp b/src/llvm_backend_general.cpp index 5e9234cec..b5338297e 100644 --- a/src/llvm_backend_general.cpp +++ b/src/llvm_backend_general.cpp @@ -91,6 +91,9 @@ gb_internal void lb_init_module(lbModule *m, Checker *c) { map_init(&m->map_cell_info_map, 0); map_init(&m->exact_value_compound_literal_addr_map, 1024); + array_init(&m->pad_types, heap_allocator()); + + m->const_dummy_builder = LLVMCreateBuilderInContext(m->ctx); } diff --git a/src/llvm_backend_utility.cpp b/src/llvm_backend_utility.cpp index 1165476be..68c1e9d1e 100644 --- a/src/llvm_backend_utility.cpp +++ b/src/llvm_backend_utility.cpp @@ -1003,6 +1003,21 @@ gb_internal i32 lb_convert_struct_index(lbModule *m, Type *t, i32 index) { } gb_internal LLVMTypeRef lb_type_padding_filler(lbModule *m, i64 padding, i64 padding_align) { + MUTEX_GUARD(&m->pad_types_mutex); + if (padding % padding_align == 0) { + for (auto pd : m->pad_types) { + if (pd.padding == padding && pd.padding_align == padding_align) { + return pd.type; + } + } + } else { + for (auto pd : m->pad_types) { + if (pd.padding == padding && pd.padding_align == 1) { + return pd.type; + } + } + } + // NOTE(bill): limit to `[N x u64]` to prevent ABI issues padding_align = gb_clamp(padding_align, 1, 8); if (padding % padding_align == 0) { @@ -1016,13 +1031,19 @@ gb_internal LLVMTypeRef lb_type_padding_filler(lbModule *m, i64 padding, i64 pad } GB_ASSERT_MSG(elem != nullptr, "Invalid lb_type_padding_filler padding and padding_align: %lld", padding_align); + + LLVMTypeRef type = nullptr; if (len != 1) { - return llvm_array_type(elem, len); + type = llvm_array_type(elem, len); } else { - return elem; + type = elem; } + array_add(&m->pad_types, lbPadType{padding, padding_align, type}); + return type; } else { - return llvm_array_type(lb_type(m, t_u8), padding); + LLVMTypeRef type = llvm_array_type(lb_type(m, t_u8), padding); + array_add(&m->pad_types, lbPadType{padding, 1, type}); + return type; } } |