diff options
| author | gingerBill <bill@gingerbill.org> | 2023-02-17 14:48:50 +0000 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2023-02-17 14:49:37 +0000 |
| commit | c08809e29d1a7acc7b158b5620f414034c2bcd7b (patch) | |
| tree | 8fd751e60763f49fd767a0fa63438b2047b05d5e /src | |
| parent | 99460c9e3293738607764d2c3d0cecddd7576e01 (diff) | |
Improve handling of passing constants to implicit immutable const ref parameters
Diffstat (limited to 'src')
| -rw-r--r-- | src/llvm_backend_proc.cpp | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/src/llvm_backend_proc.cpp b/src/llvm_backend_proc.cpp index b2ba4a864..b9ee0eeb5 100644 --- a/src/llvm_backend_proc.cpp +++ b/src/llvm_backend_proc.cpp @@ -1045,9 +1045,25 @@ gb_internal lbValue lb_emit_call(lbProcedure *p, lbValue value, Array<lbValue> c } else if (is_odin_cc) { // NOTE(bill): Odin parameters are immutable so the original value can be passed if possible // i.e. `T const &` in C++ - ptr = lb_address_from_load_or_generate_local(p, x); + if (LLVMIsConstant(x.value)) { + // NOTE(bill): if the value is already constant, then just it as a global variable + // and pass it by pointer + lbAddr addr = lb_add_global_generated(p->module, original_type, x); + lb_make_global_private_const(addr); + ptr = addr.addr; + } else { + ptr = lb_address_from_load_or_generate_local(p, x); + } } else { - ptr = lb_copy_value_to_ptr(p, x, original_type, 16); + if (LLVMIsConstant(x.value)) { + // NOTE(bill): if the value is already constant, then just it as a global variable + // and pass it by pointer + lbAddr addr = lb_add_global_generated(p->module, original_type, x); + lb_make_global_private_const(addr); + ptr = addr.addr; + } else { + ptr = lb_copy_value_to_ptr(p, x, original_type, 16); + } } array_add(&processed_args, ptr); } |