mirror of
https://github.com/odin-lang/Odin.git
synced 2026-05-01 10:34:41 +00:00
Merge pull request #2169 from odin-lang/location-byval
Ad-hoc pass source code location directly by pointer without stack copy
This commit is contained in:
@@ -457,7 +457,7 @@ lbValue lb_find_value_from_entity(lbModule *m, Entity *e);
|
||||
|
||||
void lb_store_type_case_implicit(lbProcedure *p, Ast *clause, lbValue value);
|
||||
lbAddr lb_store_range_stmt_val(lbProcedure *p, Ast *stmt_val, lbValue value);
|
||||
lbValue lb_emit_source_code_location(lbProcedure *p, String const &procedure, TokenPos const &pos);
|
||||
lbValue lb_emit_source_code_location_const(lbProcedure *p, String const &procedure, TokenPos const &pos);
|
||||
|
||||
lbValue lb_handle_param_value(lbProcedure *p, Type *parameter_type, ParameterValue const ¶m_value, TokenPos const &pos);
|
||||
|
||||
|
||||
@@ -256,7 +256,7 @@ lbValue lb_expr_untyped_const_to_typed(lbModule *m, Ast *expr, Type *t) {
|
||||
return lb_const_value(m, t, tv.value);
|
||||
}
|
||||
|
||||
lbValue lb_emit_source_code_location(lbProcedure *p, String const &procedure, TokenPos const &pos) {
|
||||
lbValue lb_emit_source_code_location_const(lbProcedure *p, String const &procedure, TokenPos const &pos) {
|
||||
lbModule *m = p->module;
|
||||
|
||||
LLVMValueRef fields[4] = {};
|
||||
@@ -271,7 +271,7 @@ lbValue lb_emit_source_code_location(lbProcedure *p, String const &procedure, To
|
||||
return res;
|
||||
}
|
||||
|
||||
lbValue lb_emit_source_code_location(lbProcedure *p, Ast *node) {
|
||||
lbValue lb_emit_source_code_location_const(lbProcedure *p, Ast *node) {
|
||||
String proc_name = {};
|
||||
if (p->entity) {
|
||||
proc_name = p->entity->token.string;
|
||||
@@ -280,11 +280,11 @@ lbValue lb_emit_source_code_location(lbProcedure *p, Ast *node) {
|
||||
if (node) {
|
||||
pos = ast_token(node).pos;
|
||||
}
|
||||
return lb_emit_source_code_location(p, proc_name, pos);
|
||||
return lb_emit_source_code_location_const(p, proc_name, pos);
|
||||
}
|
||||
|
||||
lbValue lb_emit_source_code_location_as_global(lbProcedure *p, String const &procedure, TokenPos const &pos) {
|
||||
lbValue loc = lb_emit_source_code_location(p, procedure, pos);
|
||||
lbValue loc = lb_emit_source_code_location_const(p, procedure, pos);
|
||||
lbAddr addr = lb_add_global_generated(p->module, loc.type, loc, nullptr);
|
||||
lb_make_global_private_const(addr);
|
||||
return lb_addr_load(p, addr);
|
||||
@@ -292,7 +292,7 @@ lbValue lb_emit_source_code_location_as_global(lbProcedure *p, String const &pro
|
||||
|
||||
|
||||
lbValue lb_emit_source_code_location_as_global(lbProcedure *p, Ast *node) {
|
||||
lbValue loc = lb_emit_source_code_location(p, node);
|
||||
lbValue loc = lb_emit_source_code_location_const(p, node);
|
||||
lbAddr addr = lb_add_global_generated(p->module, loc.type, loc, nullptr);
|
||||
lb_make_global_private_const(addr);
|
||||
return lb_addr_load(p, addr);
|
||||
|
||||
@@ -911,6 +911,9 @@ lbValue lb_emit_call(lbProcedure *p, lbValue value, Array<lbValue> const &args,
|
||||
auto processed_args = array_make<lbValue>(permanent_allocator(), 0, args.count);
|
||||
|
||||
{
|
||||
|
||||
bool is_odin_cc = is_calling_convention_odin(pt->Proc.calling_convention);
|
||||
|
||||
lbFunctionType *ft = lb_get_function_type(m, p, pt);
|
||||
bool return_by_pointer = ft->ret.kind == lbArg_Indirect;
|
||||
|
||||
@@ -946,8 +949,12 @@ lbValue lb_emit_call(lbProcedure *p, lbValue value, Array<lbValue> const &args,
|
||||
} else if (arg->kind == lbArg_Indirect) {
|
||||
lbValue ptr = {};
|
||||
if (arg->is_byval) {
|
||||
ptr = lb_copy_value_to_ptr(p, x, original_type, arg->byval_alignment);
|
||||
} else if (is_calling_convention_odin(pt->Proc.calling_convention)) {
|
||||
if (is_odin_cc && are_types_identical(original_type, t_source_code_location)) {
|
||||
ptr = lb_address_from_load_or_generate_local(p, x);
|
||||
} else {
|
||||
ptr = lb_copy_value_to_ptr(p, x, original_type, arg->byval_alignment);
|
||||
}
|
||||
} 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);
|
||||
|
||||
@@ -235,7 +235,7 @@ void lb_setup_type_info_data(lbProcedure *p) { // NOTE(bill): Setup type_info da
|
||||
}
|
||||
TokenPos pos = t->Named.type_name->token.pos;
|
||||
|
||||
lbValue loc = lb_emit_source_code_location(p, proc_name, pos);
|
||||
lbValue loc = lb_emit_source_code_location_const(p, proc_name, pos);
|
||||
|
||||
LLVMValueRef vals[4] = {
|
||||
lb_const_string(p->module, t->Named.type_name->token.string).value,
|
||||
|
||||
Reference in New Issue
Block a user