authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-09-10 09:46:15-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-09-10 09:46:15-04:00
logfbe5737c84c783cd31e6e2d595fc47eb782c5e3c
tree177994e0311f406f95273af408dd13b942acc921
parentc0bdcc7417a23d338dc1df6bd74b30fe6e3d1a1a
signaturelock-open Commit is signed but in an unrecognized format.

stage1: always optimize blake and softfloat even in debug mode


8 files changed, 94 insertions(+), 47 deletions(-)

CMakeLists.txt+11-3
......@@ -390,7 +390,7 @@ if(MSVC)
390390 )
391391else()
392392 set_target_properties(embedded_softfloat PROPERTIES
393 COMPILE_FLAGS "-std=c99"
393 COMPILE_FLAGS "-std=c99 -O3"
394394 )
395395endif()
396396target_include_directories(embedded_softfloat PUBLIC
......@@ -407,10 +407,9 @@ set(ZIG_SOURCES
407407 "${CMAKE_SOURCE_DIR}/src/ast_render.cpp"
408408 "${CMAKE_SOURCE_DIR}/src/bigfloat.cpp"
409409 "${CMAKE_SOURCE_DIR}/src/bigint.cpp"
410 "${CMAKE_SOURCE_DIR}/src/blake2b.cpp"
411410 "${CMAKE_SOURCE_DIR}/src/buffer.cpp"
412 "${CMAKE_SOURCE_DIR}/src/cache_hash.cpp"
413411 "${CMAKE_SOURCE_DIR}/src/c_tokenizer.cpp"
412 "${CMAKE_SOURCE_DIR}/src/cache_hash.cpp"
414413 "${CMAKE_SOURCE_DIR}/src/codegen.cpp"
415414 "${CMAKE_SOURCE_DIR}/src/errmsg.cpp"
416415 "${CMAKE_SOURCE_DIR}/src/error.cpp"
......@@ -426,6 +425,9 @@ set(ZIG_SOURCES
426425 "${CMAKE_SOURCE_DIR}/src/util.cpp"
427426 "${CMAKE_SOURCE_DIR}/src/translate_c.cpp"
428427)
428set(ZIG_SOURCES_O3
429 "${CMAKE_SOURCE_DIR}/src/blake2b.cpp"
430)
429431set(ZIG_CPP_SOURCES
430432 "${CMAKE_SOURCE_DIR}/src/zig_llvm.cpp"
431433 "${CMAKE_SOURCE_DIR}/src/windows_sdk.cpp"
......@@ -813,6 +815,11 @@ set_target_properties(zig_cpp PROPERTIES
813815 COMPILE_FLAGS ${EXE_CFLAGS}
814816)
815817
818add_library(zig_O3 STATIC ${ZIG_SOURCES_O3})
819set_target_properties(zig_O3 PROPERTIES
820 COMPILE_FLAGS "${EXE_CFLAGS} -O3"
821)
822
816823add_executable(zig ${ZIG_SOURCES})
817824set_target_properties(zig PROPERTIES
818825 COMPILE_FLAGS ${EXE_CFLAGS}
......@@ -821,6 +828,7 @@ set_target_properties(zig PROPERTIES
821828
822829target_link_libraries(zig LINK_PUBLIC
823830 zig_cpp
831 zig_O3
824832 ${SOFTFLOAT_LIBRARIES}
825833 ${CLANG_LIBRARIES}
826834 ${LLD_LIBRARIES}
src/all_types.hpp+4
......@@ -10,6 +10,7 @@
1010
1111#include "list.hpp"
1212#include "buffer.hpp"
13#include "cache_hash.hpp"
1314#include "zig_llvm.h"
1415#include "hash_map.hpp"
1516#include "errmsg.hpp"
......@@ -1613,7 +1614,10 @@ struct CodeGen {
16131614 ZigType *entry_promise;
16141615 } builtin_types;
16151616
1617 CacheHash cache_hash;
1618
16161619 //////////////////////////// Participates in Input Parameter Cache Hash
1620 Buf *compiler_id;
16171621 ZigList<LinkLib *> link_libs_list;
16181622 // add -framework [name] args to linker
16191623 ZigList<Buf *> darwin_frameworks;
src/cache_hash.cpp+4
......@@ -6,6 +6,7 @@
66 */
77
88#include "cache_hash.hpp"
9#include "all_types.hpp"
910#include "buffer.hpp"
1011#include "os.hpp"
1112
......@@ -219,6 +220,9 @@ Error cache_hit(CacheHash *ch, Buf *out_digest) {
219220
220221 buf_append_str(ch->manifest_file_path, ".txt");
221222
223 if ((err = os_make_path(ch->manifest_dir)))
224 return err;
225
222226 if ((err = os_file_open_lock_rw(ch->manifest_file_path, &ch->manifest_file)))
223227 return err;
224228
src/cache_hash.hpp+2-1
......@@ -8,10 +8,11 @@
88#ifndef ZIG_CACHE_HASH_HPP
99#define ZIG_CACHE_HASH_HPP
1010
11#include "all_types.hpp"
1211#include "blake2.h"
1312#include "os.hpp"
1413
14struct LinkLib;
15
1516struct CacheHashFile {
1617 Buf *path;
1718 OsTimeStamp mtime;
src/codegen.cpp+55-36
......@@ -88,12 +88,13 @@ static const char *symbols_that_llvm_depends_on[] = {
8888};
8989
9090CodeGen *codegen_create(Buf *root_src_path, const ZigTarget *target, OutType out_type, BuildMode build_mode,
91 Buf *zig_lib_dir)
91 Buf *zig_lib_dir, Buf *compiler_id)
9292{
9393 CodeGen *g = allocate<CodeGen>(1);
9494
9595 codegen_add_time_event(g, "Initialize");
9696
97 g->compiler_id = compiler_id;
9798 g->zig_lib_dir = zig_lib_dir;
9899
99100 g->zig_std_dir = buf_alloc();
......@@ -7675,44 +7676,62 @@ void codegen_add_time_event(CodeGen *g, const char *name) {
76757676}
76767677
76777678
7678//// Called before init()
7679//static bool build_with_cache(CodeGen *g) {
7680// // TODO zig exe & dynamic libraries
7681// // should be in main.cpp I think. only needs to happen
7682// // once on startup.
7683//
7684// CacheHash comp;
7685// cache_init(&comp);
7686//
7687// add_cache_buf(&blake, g->root_out_name);
7688// add_cache_buf_opt(&blake, get_resolved_root_src_path(g)); // Root source file
7689// add_cache_list_of_link_lib(&blake, g->link_libs_list.items, g->link_libs_list.length);
7690// add_cache_list_of_buf(&blake, g->darwin_frameworks.items, g->darwin_frameworks.length);
7691// add_cache_list_of_buf(&blake, g->rpath_list.items, g->rpath_list.length);
7692// add_cache_int(&blake, g->emit_file_type);
7693// add_cache_int(&blake, g->build_mode);
7694// add_cache_int(&blake, g->out_type);
7695// // TODO the rest of the struct CodeGen fields
7696//
7697// uint8_t bin_digest[48];
7698// rc = blake2b_final(&blake, bin_digest, 48);
7699// assert(rc == 0);
7700//
7701// Buf b64_digest = BUF_INIT;
7702// buf_resize(&b64_digest, 64);
7703// base64_encode(buf_to_slice(&b64_digest), {bin_digest, 48});
7704//
7705// fprintf(stderr, "input params hash: %s\n", buf_ptr(&b64_digest));
7706// // TODO next look for a manifest file that has all the files from the input parameters
7707// // use that to construct the real hash, which looks up the output directory and another manifest file
7708//
7709// return false;
7710//}
7679// Called before init()
7680static Error check_cache(CodeGen *g, Buf *manifest_dir, Buf *digest) {
7681 Error err;
7682
7683 CacheHash *ch = &g->cache_hash;
7684 cache_init(ch, manifest_dir);
7685
7686 cache_buf(ch, g->compiler_id);
7687 cache_buf(ch, g->root_out_name);
7688 cache_file(ch, get_resolved_root_src_path(g)); // Root source file
7689 cache_list_of_link_lib(ch, g->link_libs_list.items, g->link_libs_list.length);
7690 cache_list_of_buf(ch, g->darwin_frameworks.items, g->darwin_frameworks.length);
7691 cache_list_of_buf(ch, g->rpath_list.items, g->rpath_list.length);
7692 cache_int(ch, g->emit_file_type);
7693 cache_int(ch, g->build_mode);
7694 cache_int(ch, g->out_type);
7695 // TODO the rest of the struct CodeGen fields
7696
7697 buf_resize(digest, 0);
7698 if ((err = cache_hit(ch, digest)))
7699 return err;
7700
7701 return ErrorNone;
7702}
77117703
77127704void codegen_build(CodeGen *g) {
7705 Error err;
77137706 assert(g->out_type != OutTypeUnknown);
7714 //if (build_with_cache(g))
7715 // return;
7707
7708 Buf app_data_dir = BUF_INIT;
7709 if ((err = os_get_app_data_dir(&app_data_dir, "zig"))) {
7710 fprintf(stderr, "Unable to get app data dir: %s\n", err_str(err));
7711 exit(1);
7712 }
7713 Buf *stage1_dir = buf_alloc();
7714 os_path_join(&app_data_dir, buf_create_from_str("stage1"), stage1_dir);
7715
7716 Buf *manifest_dir = buf_alloc();
7717 os_path_join(stage1_dir, buf_create_from_str("build"), manifest_dir);
7718
7719 Buf digest = BUF_INIT;
7720 if ((err = check_cache(g, manifest_dir, &digest))) {
7721 fprintf(stderr, "Unable to check cache: %s\n", err_str(err));
7722 exit(1);
7723 }
7724 if (buf_len(&digest) != 0) {
7725 Buf *artifact_dir = buf_alloc();
7726 os_path_join(stage1_dir, buf_create_from_str("artifact"), artifact_dir);
7727
7728 Buf *this_artifact_dir = buf_alloc();
7729 os_path_join(artifact_dir, &digest, this_artifact_dir);
7730
7731 fprintf(stderr, "copy artifacts from %s\n", buf_ptr(this_artifact_dir));
7732 return;
7733 }
7734
77167735 init(g);
77177736
77187737 codegen_add_time_event(g, "Semantic Analysis");
src/codegen.hpp+1-1
......@@ -15,7 +15,7 @@
1515#include <stdio.h>
1616
1717CodeGen *codegen_create(Buf *root_src_path, const ZigTarget *target, OutType out_type, BuildMode build_mode,
18 Buf *zig_lib_dir);
18 Buf *zig_lib_dir, Buf *compiler_id);
1919
2020void codegen_set_clang_argv(CodeGen *codegen, const char **args, size_t len);
2121void codegen_set_llvm_argv(CodeGen *codegen, const char **args, size_t len);
src/link.cpp+1-1
......@@ -34,7 +34,7 @@ static const char *get_libc_static_file(CodeGen *g, const char *file) {
3434static Buf *build_o_raw(CodeGen *parent_gen, const char *oname, Buf *full_path) {
3535 ZigTarget *child_target = parent_gen->is_native_target ? nullptr : &parent_gen->zig_target;
3636 CodeGen *child_gen = codegen_create(full_path, child_target, OutTypeObj, parent_gen->build_mode,
37 parent_gen->zig_lib_dir);
37 parent_gen->zig_lib_dir, parent_gen->compiler_id);
3838
3939 child_gen->want_h_file = false;
4040 child_gen->verbose_tokenize = parent_gen->verbose_tokenize;
src/main.cpp+16-5
......@@ -274,8 +274,6 @@ static Error get_compiler_id(Buf **result) {
274274 Buf *manifest_dir = buf_alloc();
275275 os_path_join(stage1_dir, buf_create_from_str("exe"), manifest_dir);
276276
277 if ((err = os_make_path(manifest_dir)))
278 return err;
279277 CacheHash cache_hash;
280278 CacheHash *ch = &cache_hash;
281279 cache_init(ch, manifest_dir);
......@@ -432,8 +430,14 @@ int main(int argc, char **argv) {
432430 Buf *build_runner_path = buf_alloc();
433431 os_path_join(special_dir, buf_create_from_str("build_runner.zig"), build_runner_path);
434432
433 Buf *compiler_id;
434 if ((err = get_compiler_id(&compiler_id))) {
435 fprintf(stderr, "Unable to determine compiler id: %s\n", err_str(err));
436 return EXIT_FAILURE;
437 }
435438
436 CodeGen *g = codegen_create(build_runner_path, nullptr, OutTypeExe, BuildModeDebug, zig_lib_dir_buf);
439 CodeGen *g = codegen_create(build_runner_path, nullptr, OutTypeExe, BuildModeDebug, zig_lib_dir_buf,
440 compiler_id);
437441 codegen_set_out_name(g, buf_create_from_str("build"));
438442
439443 Buf *build_file_buf = buf_create_from_str(build_file);
......@@ -796,7 +800,7 @@ int main(int argc, char **argv) {
796800 switch (cmd) {
797801 case CmdBuiltin: {
798802 Buf *zig_lib_dir_buf = resolve_zig_lib_dir();
799 CodeGen *g = codegen_create(nullptr, target, out_type, build_mode, zig_lib_dir_buf);
803 CodeGen *g = codegen_create(nullptr, target, out_type, build_mode, zig_lib_dir_buf, nullptr);
800804 Buf *builtin_source = codegen_generate_builtin_source(g);
801805 if (fwrite(buf_ptr(builtin_source), 1, buf_len(builtin_source), stdout) != buf_len(builtin_source)) {
802806 fprintf(stderr, "unable to write to stdout: %s\n", strerror(ferror(stdout)));
......@@ -871,7 +875,14 @@ int main(int argc, char **argv) {
871875
872876 Buf *zig_lib_dir_buf = resolve_zig_lib_dir();
873877
874 CodeGen *g = codegen_create(zig_root_source_file, target, out_type, build_mode, zig_lib_dir_buf);
878 Buf *compiler_id;
879 if ((err = get_compiler_id(&compiler_id))) {
880 fprintf(stderr, "Unable to determine compiler id: %s\n", err_str(err));
881 return EXIT_FAILURE;
882 }
883
884 CodeGen *g = codegen_create(zig_root_source_file, target, out_type, build_mode, zig_lib_dir_buf,
885 compiler_id);
875886 codegen_set_out_name(g, buf_out_name);
876887 codegen_set_lib_version(g, ver_major, ver_minor, ver_patch);
877888 codegen_set_is_test(g, cmd == CmdTest);