Browse Source

Ad-hoc pass source code location directly by pointer without stack copy

gingerBill 2 years ago
parent
commit
c39ef1b25c
4 changed files with 16 additions and 9 deletions
  1. 1 1
      src/llvm_backend.hpp
  2. 5 5
      src/llvm_backend_const.cpp
  3. 9 2
      src/llvm_backend_proc.cpp
  4. 1 1
      src/llvm_backend_type.cpp

+ 1 - 1
src/llvm_backend.hpp

@@ -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);
 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);
 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 &param_value, TokenPos const &pos);
 lbValue lb_handle_param_value(lbProcedure *p, Type *parameter_type, ParameterValue const &param_value, TokenPos const &pos);
 
 

+ 5 - 5
src/llvm_backend_const.cpp

@@ -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);
 	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;
 	lbModule *m = p->module;
 
 
 	LLVMValueRef fields[4] = {};
 	LLVMValueRef fields[4] = {};
@@ -271,7 +271,7 @@ lbValue lb_emit_source_code_location(lbProcedure *p, String const &procedure, To
 	return res;
 	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 = {};
 	String proc_name = {};
 	if (p->entity) {
 	if (p->entity) {
 		proc_name = p->entity->token.string;
 		proc_name = p->entity->token.string;
@@ -280,11 +280,11 @@ lbValue lb_emit_source_code_location(lbProcedure *p, Ast *node) {
 	if (node) {
 	if (node) {
 		pos = ast_token(node).pos;
 		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 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);
 	lbAddr addr = lb_add_global_generated(p->module, loc.type, loc, nullptr);
 	lb_make_global_private_const(addr);
 	lb_make_global_private_const(addr);
 	return lb_addr_load(p, 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 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);
 	lbAddr addr = lb_add_global_generated(p->module, loc.type, loc, nullptr);
 	lb_make_global_private_const(addr);
 	lb_make_global_private_const(addr);
 	return lb_addr_load(p, addr);
 	return lb_addr_load(p, addr);

+ 9 - 2
src/llvm_backend_proc.cpp

@@ -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);
 	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);
 		lbFunctionType *ft = lb_get_function_type(m, p, pt);
 		bool return_by_pointer = ft->ret.kind == lbArg_Indirect;
 		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) {
 			} else if (arg->kind == lbArg_Indirect) {
 				lbValue ptr = {};
 				lbValue ptr = {};
 				if (arg->is_byval) {
 				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
 					// NOTE(bill): Odin parameters are immutable so the original value can be passed if possible
 					// i.e. `T const &` in C++
 					// i.e. `T const &` in C++
 					ptr = lb_address_from_load_or_generate_local(p, x);
 					ptr = lb_address_from_load_or_generate_local(p, x);

+ 1 - 1
src/llvm_backend_type.cpp

@@ -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;
 			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] = {
 			LLVMValueRef vals[4] = {
 				lb_const_string(p->module, t->Named.type_name->token.string).value,
 				lb_const_string(p->module, t->Named.type_name->token.string).value,