From d28f6144a4a5c270078b9f5436066113f345b3e8 Mon Sep 17 00:00:00 2001 From: atil Date: Fri, 19 Mar 2021 09:52:53 +0300 Subject: [PATCH 1/4] early memcpyopt --- src/build_settings.cpp | 2 +- src/main.cpp | 20 +++++++++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/build_settings.cpp b/src/build_settings.cpp index e1192eea5..f55bc631e 100644 --- a/src/build_settings.cpp +++ b/src/build_settings.cpp @@ -873,7 +873,7 @@ void init_build_context(TargetMetrics *cross_target) { // -memcpyopt: MemCpy optimization } if (bc->ODIN_DEBUG == false) { - opt_flags = gb_string_appendc(opt_flags, "-mem2reg -memcpyopt -die "); + opt_flags = gb_string_appendc(opt_flags, "-mem2reg -die "); } diff --git a/src/main.cpp b/src/main.cpp index 0f6208134..81253f53c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1506,8 +1506,16 @@ void remove_temp_files(String output_base) { i32 exec_llvm_opt(String output_base) { #if defined(GB_SYSTEM_WINDOWS) // 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 " + "\"%.*sbin/opt\" \"%.*s.ll\" -o \"memcpy_pass_%.*s.bc\" %.*s " + "", + LIT(build_context.ODIN_ROOT), + LIT(output_base), LIT(output_base), + LIT(build_context.opt_flags)); + + || system_exec_command_line_app("llvm-opt", + "\"%.*sbin/opt\" \"memcpy_pass_%.*s.bc\" -o \"%.*s.bc\" %.*s " "", LIT(build_context.ODIN_ROOT), LIT(output_base), LIT(output_base), @@ -1515,8 +1523,14 @@ i32 exec_llvm_opt(String output_base) { #else // 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 - 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 \"memcpy_pass_%.*s.bc\" -memcpyopt" + "", + LIT(output_base), LIT(output_base)) + + || system_exec_command_line_app("llvm-opt", + "opt \"memcpy_pass_%.*s.bc\" -o \"%.*s.bc\" %.*s " "", LIT(output_base), LIT(output_base), LIT(build_context.opt_flags)); From 2f4902c9b947efefec572ca81b5a367edaa9a99b Mon Sep 17 00:00:00 2001 From: atil Date: Fri, 19 Mar 2021 09:54:28 +0300 Subject: [PATCH 2/4] fixtypo --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 81253f53c..914dc1dbe 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1512,7 +1512,7 @@ i32 exec_llvm_opt(String output_base) { "", LIT(build_context.ODIN_ROOT), LIT(output_base), LIT(output_base), - LIT(build_context.opt_flags)); + LIT(build_context.opt_flags)) || system_exec_command_line_app("llvm-opt", "\"%.*sbin/opt\" \"memcpy_pass_%.*s.bc\" -o \"%.*s.bc\" %.*s " From 2c0ddfb5db1a06c76f94022e6ff505948e98afd1 Mon Sep 17 00:00:00 2001 From: atil Date: Fri, 19 Mar 2021 09:57:38 +0300 Subject: [PATCH 3/4] fixtypo --- src/main.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 914dc1dbe..9d048ca27 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1508,11 +1508,10 @@ i32 exec_llvm_opt(String output_base) { // For more passes arguments: http://llvm.org/docs/Passes.html return system_exec_command_line_app("llvm-opt", - "\"%.*sbin/opt\" \"%.*s.ll\" -o \"memcpy_pass_%.*s.bc\" %.*s " + "\"%.*sbin/opt\" \"%.*s.ll\" -o \"memcpy_pass_%.*s.bc\" -memcpyopt" "", LIT(build_context.ODIN_ROOT), - LIT(output_base), LIT(output_base), - LIT(build_context.opt_flags)) + LIT(output_base), LIT(output_base)) || system_exec_command_line_app("llvm-opt", "\"%.*sbin/opt\" \"memcpy_pass_%.*s.bc\" -o \"%.*s.bc\" %.*s " From 88b8052532eb8ccdf673226e8b4862bfe8b56e12 Mon Sep 17 00:00:00 2001 From: Atil Kurtulmus Date: Fri, 19 Mar 2021 07:23:17 +0300 Subject: [PATCH 4/4] fix windows --- src/main.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 9d048ca27..2496c87ae 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1477,7 +1477,7 @@ void show_timings(Checker *c, Timings *t) { void remove_temp_files(String output_base) { if (build_context.keep_temp_files) return; - auto data = array_make(heap_allocator(), output_base.len + 10); + auto data = array_make(heap_allocator(), output_base.len + 30); defer (array_free(&data)); isize n = output_base.len; @@ -1488,6 +1488,7 @@ void remove_temp_files(String output_base) { } while (0) EXT_REMOVE(".ll"); EXT_REMOVE(".bc"); + EXT_REMOVE("_memcpy_pass.bc"); if (build_context.build_mode != BuildMode_Object && !build_context.keep_object_files) { #if defined(GB_SYSTEM_WINDOWS) EXT_REMOVE(".obj"); @@ -1507,14 +1508,14 @@ i32 exec_llvm_opt(String output_base) { #if defined(GB_SYSTEM_WINDOWS) // For more passes arguments: http://llvm.org/docs/Passes.html - return system_exec_command_line_app("llvm-opt", - "\"%.*sbin/opt\" \"%.*s.ll\" -o \"memcpy_pass_%.*s.bc\" -memcpyopt" + 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\" \"memcpy_pass_%.*s.bc\" -o \"%.*s.bc\" %.*s " + "\"%.*sbin/opt\" \"%.*s_memcpy_pass.bc\" -o \"%.*s.bc\" %.*s " "", LIT(build_context.ODIN_ROOT), LIT(output_base), LIT(output_base), @@ -1524,12 +1525,12 @@ i32 exec_llvm_opt(String output_base) { // 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 \"memcpy_pass_%.*s.bc\" -memcpyopt" + "opt \"%.*s.ll\" -o \"%.*s_memcpy_pass.bc\" -memcpyopt" "", LIT(output_base), LIT(output_base)) || system_exec_command_line_app("llvm-opt", - "opt \"memcpy_pass_%.*s.bc\" -o \"%.*s.bc\" %.*s " + "opt \"%.*s_memcpy_pass.bc\" -o \"%.*s.bc\" %.*s " "", LIT(output_base), LIT(output_base), LIT(build_context.opt_flags));