Pārlūkot izejas kodu

Reuse slice variable for variadic parameters

gingerBill 1 gadu atpakaļ
vecāks
revīzija
5027c7081e
2 mainītis faili ar 7 papildinājumiem un 2 dzēšanām
  1. 1 0
      src/llvm_backend.hpp
  2. 6 2
      src/llvm_backend_proc.cpp

+ 1 - 0
src/llvm_backend.hpp

@@ -299,6 +299,7 @@ enum lbProcedureFlag : u32 {
 struct lbVariadicReuseData {
 	Type *slice_type;
 	lbAddr base_array;
+	lbAddr slice_addr;
 };
 
 struct lbProcedure {

+ 6 - 2
src/llvm_backend_proc.cpp

@@ -3457,9 +3457,12 @@ gb_internal lbValue lb_build_call_expr_internal(lbProcedure *p, Ast *expr) {
 					isize slice_len = var_args.count;
 					if (slice_len > 0) {
 						lbAddr base_array = {};
+						lbAddr slice = {};
+
 						for (auto const &vr : p->variadic_reuses) {
 							if (are_types_identical(vr.slice_type, slice_type)) {
 								base_array = vr.base_array;
+								slice = vr.slice_addr;
 								break;
 							}
 						}
@@ -3468,14 +3471,15 @@ gb_internal lbValue lb_build_call_expr_internal(lbProcedure *p, Ast *expr) {
 							for (auto const &vr : d->variadic_reuses) {
 								if (are_types_identical(vr.slice_type, slice_type)) {
 									base_array = lb_add_local_generated(p, alloc_type_array(elem_type, vr.max_count), true);
-									array_add(&p->variadic_reuses, lbVariadicReuseData{slice_type, base_array});
+									slice = lb_add_local_generated(p, slice_type, true);
+									array_add(&p->variadic_reuses, lbVariadicReuseData{slice_type, base_array, slice});
 									break;
 								}
 							}
 						}
 						GB_ASSERT(base_array.addr.value != nullptr);
+						GB_ASSERT(slice.addr.value != nullptr);
 
-						lbAddr slice = lb_add_local_generated(p, slice_type, true);
 
 						for (isize i = 0; i < var_args.count; i++) {
 							lbValue addr = lb_emit_array_epi(p, base_array.addr, cast(i32)i);