Merge pull request #875 from atkurtul/master

Run an early memcpy pass regardless of the opt flag and return large structs by pointer on linux
This commit is contained in:
gingerBill
2021-03-19 11:07:12 +00:00
committed by GitHub
4 changed files with 23 additions and 11 deletions
+1 -1
View File
@@ -873,7 +873,7 @@ void init_build_context(TargetMetrics *cross_target) {
// -memcpyopt: MemCpy optimization // -memcpyopt: MemCpy optimization
} }
if (bc->ODIN_DEBUG == false) { if (bc->ODIN_DEBUG == false) {
opt_flags = gb_string_appendc(opt_flags, "-mem2reg -memcpyopt -die "); opt_flags = gb_string_appendc(opt_flags, "-mem2reg -die ");
} }
+1 -1
View File
@@ -2423,7 +2423,7 @@ bool abi_compat_return_by_pointer(gbAllocator a, ProcCallingConvention cc, Type
} }
} }
if (build_context.ODIN_OS == "windows") { if (build_context.ODIN_OS == "windows" || build_context.ODIN_OS == "linux" ) {
i64 size = 8*type_size_of(abi_return_type); i64 size = 8*type_size_of(abi_return_type);
switch (size) { switch (size) {
case 0: case 0:
+2 -4
View File
@@ -339,8 +339,7 @@ void ir_print_proc_type_without_pointer(irFileBuffer *f, irModule *m, Type *t) {
// ir_fprintf(f, "* sret noalias "); // ir_fprintf(f, "* sret noalias ");
// ir_write_string(f, str_lit("* noalias ")); // ir_write_string(f, str_lit("* noalias "));
ir_write_string(f, str_lit("*")); ir_write_string(f, str_lit("*"));
if (build_context.ODIN_OS == "darwin" || if (build_context.ODIN_OS == "darwin") {
build_context.ODIN_OS == "linux") {
ir_fprintf(f, " byval"); ir_fprintf(f, " byval");
} }
if (param_count > 0 || t->Proc.calling_convention == ProcCC_Odin) { if (param_count > 0 || t->Proc.calling_convention == ProcCC_Odin) {
@@ -2456,8 +2455,7 @@ void ir_print_proc(irFileBuffer *f, irModule *m, irProcedure *proc) {
if (proc_type->return_by_pointer) { if (proc_type->return_by_pointer) {
ir_print_type(f, m, reduce_tuple_to_single_type(proc_type->results)); ir_print_type(f, m, reduce_tuple_to_single_type(proc_type->results));
ir_write_str_lit(f, "* sret noalias "); ir_write_str_lit(f, "* sret noalias ");
if (build_context.ODIN_OS == "darwin" || if (build_context.ODIN_OS == "darwin") {
build_context.ODIN_OS == "linux") {
ir_fprintf(f, "byval "); ir_fprintf(f, "byval ");
} }
ir_write_str_lit(f, "%agg.result"); ir_write_str_lit(f, "%agg.result");
+19 -5
View File
@@ -1477,7 +1477,7 @@ void show_timings(Checker *c, Timings *t) {
void remove_temp_files(String output_base) { void remove_temp_files(String output_base) {
if (build_context.keep_temp_files) return; if (build_context.keep_temp_files) return;
auto data = array_make<u8>(heap_allocator(), output_base.len + 10); auto data = array_make<u8>(heap_allocator(), output_base.len + 30);
defer (array_free(&data)); defer (array_free(&data));
isize n = output_base.len; isize n = output_base.len;
@@ -1488,6 +1488,7 @@ void remove_temp_files(String output_base) {
} while (0) } while (0)
EXT_REMOVE(".ll"); EXT_REMOVE(".ll");
EXT_REMOVE(".bc"); EXT_REMOVE(".bc");
EXT_REMOVE("_memcpy_pass.bc");
if (build_context.build_mode != BuildMode_Object && !build_context.keep_object_files) { if (build_context.build_mode != BuildMode_Object && !build_context.keep_object_files) {
#if defined(GB_SYSTEM_WINDOWS) #if defined(GB_SYSTEM_WINDOWS)
EXT_REMOVE(".obj"); EXT_REMOVE(".obj");
@@ -1506,8 +1507,15 @@ void remove_temp_files(String output_base) {
i32 exec_llvm_opt(String output_base) { i32 exec_llvm_opt(String output_base) {
#if defined(GB_SYSTEM_WINDOWS) #if defined(GB_SYSTEM_WINDOWS)
// For more passes arguments: http://llvm.org/docs/Passes.html // For more passes arguments: http://llvm.org/docs/Passes.html
return system_exec_command_line_app("llvm-opt",
"\"%.*sbin/opt\" \"%.*s.ll\" -o \"%.*s.bc\" %.*s " return system_exec_command_line_app("llvm-opt",
"\"%.*sbin/opt\" \"%.*s.ll\" -o \"%.*s_memcpy_pass.bc\" -memcpyopt"
"",
LIT(build_context.ODIN_ROOT),
LIT(output_base), LIT(output_base))
|| system_exec_command_line_app("llvm-opt",
"\"%.*sbin/opt\" \"%.*s_memcpy_pass.bc\" -o \"%.*s.bc\" %.*s "
"", "",
LIT(build_context.ODIN_ROOT), LIT(build_context.ODIN_ROOT),
LIT(output_base), LIT(output_base), LIT(output_base), LIT(output_base),
@@ -1515,8 +1523,14 @@ i32 exec_llvm_opt(String output_base) {
#else #else
// NOTE(zangent): This is separate because it seems that LLVM tools are packaged // NOTE(zangent): This is separate because it seems that LLVM tools are packaged
// with the Windows version, while they will be system-provided on MacOS and GNU/Linux // with the Windows version, while they will be system-provided on MacOS and GNU/Linux
return system_exec_command_line_app("llvm-opt",
"opt \"%.*s.ll\" -o \"%.*s.bc\" %.*s " return system_exec_command_line_app("llvm-opt",
"opt \"%.*s.ll\" -o \"%.*s_memcpy_pass.bc\" -memcpyopt"
"",
LIT(output_base), LIT(output_base))
|| system_exec_command_line_app("llvm-opt",
"opt \"%.*s_memcpy_pass.bc\" -o \"%.*s.bc\" %.*s "
"", "",
LIT(output_base), LIT(output_base), LIT(output_base), LIT(output_base),
LIT(build_context.opt_flags)); LIT(build_context.opt_flags));