stage1: always optimize blake and softfloat even in debug mode
parent
c0bdcc7417
commit
fbe5737c84
|
@ -390,7 +390,7 @@ if(MSVC)
|
||||||
)
|
)
|
||||||
else()
|
else()
|
||||||
set_target_properties(embedded_softfloat PROPERTIES
|
set_target_properties(embedded_softfloat PROPERTIES
|
||||||
COMPILE_FLAGS "-std=c99"
|
COMPILE_FLAGS "-std=c99 -O3"
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
target_include_directories(embedded_softfloat PUBLIC
|
target_include_directories(embedded_softfloat PUBLIC
|
||||||
|
@ -407,10 +407,9 @@ set(ZIG_SOURCES
|
||||||
"${CMAKE_SOURCE_DIR}/src/ast_render.cpp"
|
"${CMAKE_SOURCE_DIR}/src/ast_render.cpp"
|
||||||
"${CMAKE_SOURCE_DIR}/src/bigfloat.cpp"
|
"${CMAKE_SOURCE_DIR}/src/bigfloat.cpp"
|
||||||
"${CMAKE_SOURCE_DIR}/src/bigint.cpp"
|
"${CMAKE_SOURCE_DIR}/src/bigint.cpp"
|
||||||
"${CMAKE_SOURCE_DIR}/src/blake2b.cpp"
|
|
||||||
"${CMAKE_SOURCE_DIR}/src/buffer.cpp"
|
"${CMAKE_SOURCE_DIR}/src/buffer.cpp"
|
||||||
"${CMAKE_SOURCE_DIR}/src/cache_hash.cpp"
|
|
||||||
"${CMAKE_SOURCE_DIR}/src/c_tokenizer.cpp"
|
"${CMAKE_SOURCE_DIR}/src/c_tokenizer.cpp"
|
||||||
|
"${CMAKE_SOURCE_DIR}/src/cache_hash.cpp"
|
||||||
"${CMAKE_SOURCE_DIR}/src/codegen.cpp"
|
"${CMAKE_SOURCE_DIR}/src/codegen.cpp"
|
||||||
"${CMAKE_SOURCE_DIR}/src/errmsg.cpp"
|
"${CMAKE_SOURCE_DIR}/src/errmsg.cpp"
|
||||||
"${CMAKE_SOURCE_DIR}/src/error.cpp"
|
"${CMAKE_SOURCE_DIR}/src/error.cpp"
|
||||||
|
@ -426,6 +425,9 @@ set(ZIG_SOURCES
|
||||||
"${CMAKE_SOURCE_DIR}/src/util.cpp"
|
"${CMAKE_SOURCE_DIR}/src/util.cpp"
|
||||||
"${CMAKE_SOURCE_DIR}/src/translate_c.cpp"
|
"${CMAKE_SOURCE_DIR}/src/translate_c.cpp"
|
||||||
)
|
)
|
||||||
|
set(ZIG_SOURCES_O3
|
||||||
|
"${CMAKE_SOURCE_DIR}/src/blake2b.cpp"
|
||||||
|
)
|
||||||
set(ZIG_CPP_SOURCES
|
set(ZIG_CPP_SOURCES
|
||||||
"${CMAKE_SOURCE_DIR}/src/zig_llvm.cpp"
|
"${CMAKE_SOURCE_DIR}/src/zig_llvm.cpp"
|
||||||
"${CMAKE_SOURCE_DIR}/src/windows_sdk.cpp"
|
"${CMAKE_SOURCE_DIR}/src/windows_sdk.cpp"
|
||||||
|
@ -813,6 +815,11 @@ set_target_properties(zig_cpp PROPERTIES
|
||||||
COMPILE_FLAGS ${EXE_CFLAGS}
|
COMPILE_FLAGS ${EXE_CFLAGS}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
add_library(zig_O3 STATIC ${ZIG_SOURCES_O3})
|
||||||
|
set_target_properties(zig_O3 PROPERTIES
|
||||||
|
COMPILE_FLAGS "${EXE_CFLAGS} -O3"
|
||||||
|
)
|
||||||
|
|
||||||
add_executable(zig ${ZIG_SOURCES})
|
add_executable(zig ${ZIG_SOURCES})
|
||||||
set_target_properties(zig PROPERTIES
|
set_target_properties(zig PROPERTIES
|
||||||
COMPILE_FLAGS ${EXE_CFLAGS}
|
COMPILE_FLAGS ${EXE_CFLAGS}
|
||||||
|
@ -821,6 +828,7 @@ set_target_properties(zig PROPERTIES
|
||||||
|
|
||||||
target_link_libraries(zig LINK_PUBLIC
|
target_link_libraries(zig LINK_PUBLIC
|
||||||
zig_cpp
|
zig_cpp
|
||||||
|
zig_O3
|
||||||
${SOFTFLOAT_LIBRARIES}
|
${SOFTFLOAT_LIBRARIES}
|
||||||
${CLANG_LIBRARIES}
|
${CLANG_LIBRARIES}
|
||||||
${LLD_LIBRARIES}
|
${LLD_LIBRARIES}
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
|
|
||||||
#include "list.hpp"
|
#include "list.hpp"
|
||||||
#include "buffer.hpp"
|
#include "buffer.hpp"
|
||||||
|
#include "cache_hash.hpp"
|
||||||
#include "zig_llvm.h"
|
#include "zig_llvm.h"
|
||||||
#include "hash_map.hpp"
|
#include "hash_map.hpp"
|
||||||
#include "errmsg.hpp"
|
#include "errmsg.hpp"
|
||||||
|
@ -1613,7 +1614,10 @@ struct CodeGen {
|
||||||
ZigType *entry_promise;
|
ZigType *entry_promise;
|
||||||
} builtin_types;
|
} builtin_types;
|
||||||
|
|
||||||
|
CacheHash cache_hash;
|
||||||
|
|
||||||
//////////////////////////// Participates in Input Parameter Cache Hash
|
//////////////////////////// Participates in Input Parameter Cache Hash
|
||||||
|
Buf *compiler_id;
|
||||||
ZigList<LinkLib *> link_libs_list;
|
ZigList<LinkLib *> link_libs_list;
|
||||||
// add -framework [name] args to linker
|
// add -framework [name] args to linker
|
||||||
ZigList<Buf *> darwin_frameworks;
|
ZigList<Buf *> darwin_frameworks;
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "cache_hash.hpp"
|
#include "cache_hash.hpp"
|
||||||
|
#include "all_types.hpp"
|
||||||
#include "buffer.hpp"
|
#include "buffer.hpp"
|
||||||
#include "os.hpp"
|
#include "os.hpp"
|
||||||
|
|
||||||
|
@ -219,6 +220,9 @@ Error cache_hit(CacheHash *ch, Buf *out_digest) {
|
||||||
|
|
||||||
buf_append_str(ch->manifest_file_path, ".txt");
|
buf_append_str(ch->manifest_file_path, ".txt");
|
||||||
|
|
||||||
|
if ((err = os_make_path(ch->manifest_dir)))
|
||||||
|
return err;
|
||||||
|
|
||||||
if ((err = os_file_open_lock_rw(ch->manifest_file_path, &ch->manifest_file)))
|
if ((err = os_file_open_lock_rw(ch->manifest_file_path, &ch->manifest_file)))
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
|
|
|
@ -8,10 +8,11 @@
|
||||||
#ifndef ZIG_CACHE_HASH_HPP
|
#ifndef ZIG_CACHE_HASH_HPP
|
||||||
#define ZIG_CACHE_HASH_HPP
|
#define ZIG_CACHE_HASH_HPP
|
||||||
|
|
||||||
#include "all_types.hpp"
|
|
||||||
#include "blake2.h"
|
#include "blake2.h"
|
||||||
#include "os.hpp"
|
#include "os.hpp"
|
||||||
|
|
||||||
|
struct LinkLib;
|
||||||
|
|
||||||
struct CacheHashFile {
|
struct CacheHashFile {
|
||||||
Buf *path;
|
Buf *path;
|
||||||
OsTimeStamp mtime;
|
OsTimeStamp mtime;
|
||||||
|
|
|
@ -88,12 +88,13 @@ static const char *symbols_that_llvm_depends_on[] = {
|
||||||
};
|
};
|
||||||
|
|
||||||
CodeGen *codegen_create(Buf *root_src_path, const ZigTarget *target, OutType out_type, BuildMode build_mode,
|
CodeGen *codegen_create(Buf *root_src_path, const ZigTarget *target, OutType out_type, BuildMode build_mode,
|
||||||
Buf *zig_lib_dir)
|
Buf *zig_lib_dir, Buf *compiler_id)
|
||||||
{
|
{
|
||||||
CodeGen *g = allocate<CodeGen>(1);
|
CodeGen *g = allocate<CodeGen>(1);
|
||||||
|
|
||||||
codegen_add_time_event(g, "Initialize");
|
codegen_add_time_event(g, "Initialize");
|
||||||
|
|
||||||
|
g->compiler_id = compiler_id;
|
||||||
g->zig_lib_dir = zig_lib_dir;
|
g->zig_lib_dir = zig_lib_dir;
|
||||||
|
|
||||||
g->zig_std_dir = buf_alloc();
|
g->zig_std_dir = buf_alloc();
|
||||||
|
@ -7675,44 +7676,62 @@ void codegen_add_time_event(CodeGen *g, const char *name) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//// Called before init()
|
// Called before init()
|
||||||
//static bool build_with_cache(CodeGen *g) {
|
static Error check_cache(CodeGen *g, Buf *manifest_dir, Buf *digest) {
|
||||||
// // TODO zig exe & dynamic libraries
|
Error err;
|
||||||
// // should be in main.cpp I think. only needs to happen
|
|
||||||
// // once on startup.
|
CacheHash *ch = &g->cache_hash;
|
||||||
//
|
cache_init(ch, manifest_dir);
|
||||||
// CacheHash comp;
|
|
||||||
// cache_init(&comp);
|
cache_buf(ch, g->compiler_id);
|
||||||
//
|
cache_buf(ch, g->root_out_name);
|
||||||
// add_cache_buf(&blake, g->root_out_name);
|
cache_file(ch, get_resolved_root_src_path(g)); // Root source file
|
||||||
// add_cache_buf_opt(&blake, get_resolved_root_src_path(g)); // Root source file
|
cache_list_of_link_lib(ch, g->link_libs_list.items, g->link_libs_list.length);
|
||||||
// add_cache_list_of_link_lib(&blake, g->link_libs_list.items, g->link_libs_list.length);
|
cache_list_of_buf(ch, g->darwin_frameworks.items, g->darwin_frameworks.length);
|
||||||
// add_cache_list_of_buf(&blake, g->darwin_frameworks.items, g->darwin_frameworks.length);
|
cache_list_of_buf(ch, g->rpath_list.items, g->rpath_list.length);
|
||||||
// add_cache_list_of_buf(&blake, g->rpath_list.items, g->rpath_list.length);
|
cache_int(ch, g->emit_file_type);
|
||||||
// add_cache_int(&blake, g->emit_file_type);
|
cache_int(ch, g->build_mode);
|
||||||
// add_cache_int(&blake, g->build_mode);
|
cache_int(ch, g->out_type);
|
||||||
// add_cache_int(&blake, g->out_type);
|
// TODO the rest of the struct CodeGen fields
|
||||||
// // TODO the rest of the struct CodeGen fields
|
|
||||||
//
|
buf_resize(digest, 0);
|
||||||
// uint8_t bin_digest[48];
|
if ((err = cache_hit(ch, digest)))
|
||||||
// rc = blake2b_final(&blake, bin_digest, 48);
|
return err;
|
||||||
// assert(rc == 0);
|
|
||||||
//
|
return ErrorNone;
|
||||||
// Buf b64_digest = BUF_INIT;
|
}
|
||||||
// buf_resize(&b64_digest, 64);
|
|
||||||
// base64_encode(buf_to_slice(&b64_digest), {bin_digest, 48});
|
|
||||||
//
|
|
||||||
// fprintf(stderr, "input params hash: %s\n", buf_ptr(&b64_digest));
|
|
||||||
// // TODO next look for a manifest file that has all the files from the input parameters
|
|
||||||
// // use that to construct the real hash, which looks up the output directory and another manifest file
|
|
||||||
//
|
|
||||||
// return false;
|
|
||||||
//}
|
|
||||||
|
|
||||||
void codegen_build(CodeGen *g) {
|
void codegen_build(CodeGen *g) {
|
||||||
|
Error err;
|
||||||
assert(g->out_type != OutTypeUnknown);
|
assert(g->out_type != OutTypeUnknown);
|
||||||
//if (build_with_cache(g))
|
|
||||||
// return;
|
Buf app_data_dir = BUF_INIT;
|
||||||
|
if ((err = os_get_app_data_dir(&app_data_dir, "zig"))) {
|
||||||
|
fprintf(stderr, "Unable to get app data dir: %s\n", err_str(err));
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
Buf *stage1_dir = buf_alloc();
|
||||||
|
os_path_join(&app_data_dir, buf_create_from_str("stage1"), stage1_dir);
|
||||||
|
|
||||||
|
Buf *manifest_dir = buf_alloc();
|
||||||
|
os_path_join(stage1_dir, buf_create_from_str("build"), manifest_dir);
|
||||||
|
|
||||||
|
Buf digest = BUF_INIT;
|
||||||
|
if ((err = check_cache(g, manifest_dir, &digest))) {
|
||||||
|
fprintf(stderr, "Unable to check cache: %s\n", err_str(err));
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
if (buf_len(&digest) != 0) {
|
||||||
|
Buf *artifact_dir = buf_alloc();
|
||||||
|
os_path_join(stage1_dir, buf_create_from_str("artifact"), artifact_dir);
|
||||||
|
|
||||||
|
Buf *this_artifact_dir = buf_alloc();
|
||||||
|
os_path_join(artifact_dir, &digest, this_artifact_dir);
|
||||||
|
|
||||||
|
fprintf(stderr, "copy artifacts from %s\n", buf_ptr(this_artifact_dir));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
init(g);
|
init(g);
|
||||||
|
|
||||||
codegen_add_time_event(g, "Semantic Analysis");
|
codegen_add_time_event(g, "Semantic Analysis");
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
CodeGen *codegen_create(Buf *root_src_path, const ZigTarget *target, OutType out_type, BuildMode build_mode,
|
CodeGen *codegen_create(Buf *root_src_path, const ZigTarget *target, OutType out_type, BuildMode build_mode,
|
||||||
Buf *zig_lib_dir);
|
Buf *zig_lib_dir, Buf *compiler_id);
|
||||||
|
|
||||||
void codegen_set_clang_argv(CodeGen *codegen, const char **args, size_t len);
|
void codegen_set_clang_argv(CodeGen *codegen, const char **args, size_t len);
|
||||||
void codegen_set_llvm_argv(CodeGen *codegen, const char **args, size_t len);
|
void codegen_set_llvm_argv(CodeGen *codegen, const char **args, size_t len);
|
||||||
|
|
|
@ -34,7 +34,7 @@ static const char *get_libc_static_file(CodeGen *g, const char *file) {
|
||||||
static Buf *build_o_raw(CodeGen *parent_gen, const char *oname, Buf *full_path) {
|
static Buf *build_o_raw(CodeGen *parent_gen, const char *oname, Buf *full_path) {
|
||||||
ZigTarget *child_target = parent_gen->is_native_target ? nullptr : &parent_gen->zig_target;
|
ZigTarget *child_target = parent_gen->is_native_target ? nullptr : &parent_gen->zig_target;
|
||||||
CodeGen *child_gen = codegen_create(full_path, child_target, OutTypeObj, parent_gen->build_mode,
|
CodeGen *child_gen = codegen_create(full_path, child_target, OutTypeObj, parent_gen->build_mode,
|
||||||
parent_gen->zig_lib_dir);
|
parent_gen->zig_lib_dir, parent_gen->compiler_id);
|
||||||
|
|
||||||
child_gen->want_h_file = false;
|
child_gen->want_h_file = false;
|
||||||
child_gen->verbose_tokenize = parent_gen->verbose_tokenize;
|
child_gen->verbose_tokenize = parent_gen->verbose_tokenize;
|
||||||
|
|
21
src/main.cpp
21
src/main.cpp
|
@ -274,8 +274,6 @@ static Error get_compiler_id(Buf **result) {
|
||||||
Buf *manifest_dir = buf_alloc();
|
Buf *manifest_dir = buf_alloc();
|
||||||
os_path_join(stage1_dir, buf_create_from_str("exe"), manifest_dir);
|
os_path_join(stage1_dir, buf_create_from_str("exe"), manifest_dir);
|
||||||
|
|
||||||
if ((err = os_make_path(manifest_dir)))
|
|
||||||
return err;
|
|
||||||
CacheHash cache_hash;
|
CacheHash cache_hash;
|
||||||
CacheHash *ch = &cache_hash;
|
CacheHash *ch = &cache_hash;
|
||||||
cache_init(ch, manifest_dir);
|
cache_init(ch, manifest_dir);
|
||||||
|
@ -432,8 +430,14 @@ int main(int argc, char **argv) {
|
||||||
Buf *build_runner_path = buf_alloc();
|
Buf *build_runner_path = buf_alloc();
|
||||||
os_path_join(special_dir, buf_create_from_str("build_runner.zig"), build_runner_path);
|
os_path_join(special_dir, buf_create_from_str("build_runner.zig"), build_runner_path);
|
||||||
|
|
||||||
|
Buf *compiler_id;
|
||||||
|
if ((err = get_compiler_id(&compiler_id))) {
|
||||||
|
fprintf(stderr, "Unable to determine compiler id: %s\n", err_str(err));
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
CodeGen *g = codegen_create(build_runner_path, nullptr, OutTypeExe, BuildModeDebug, zig_lib_dir_buf);
|
CodeGen *g = codegen_create(build_runner_path, nullptr, OutTypeExe, BuildModeDebug, zig_lib_dir_buf,
|
||||||
|
compiler_id);
|
||||||
codegen_set_out_name(g, buf_create_from_str("build"));
|
codegen_set_out_name(g, buf_create_from_str("build"));
|
||||||
|
|
||||||
Buf *build_file_buf = buf_create_from_str(build_file);
|
Buf *build_file_buf = buf_create_from_str(build_file);
|
||||||
|
@ -796,7 +800,7 @@ int main(int argc, char **argv) {
|
||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
case CmdBuiltin: {
|
case CmdBuiltin: {
|
||||||
Buf *zig_lib_dir_buf = resolve_zig_lib_dir();
|
Buf *zig_lib_dir_buf = resolve_zig_lib_dir();
|
||||||
CodeGen *g = codegen_create(nullptr, target, out_type, build_mode, zig_lib_dir_buf);
|
CodeGen *g = codegen_create(nullptr, target, out_type, build_mode, zig_lib_dir_buf, nullptr);
|
||||||
Buf *builtin_source = codegen_generate_builtin_source(g);
|
Buf *builtin_source = codegen_generate_builtin_source(g);
|
||||||
if (fwrite(buf_ptr(builtin_source), 1, buf_len(builtin_source), stdout) != buf_len(builtin_source)) {
|
if (fwrite(buf_ptr(builtin_source), 1, buf_len(builtin_source), stdout) != buf_len(builtin_source)) {
|
||||||
fprintf(stderr, "unable to write to stdout: %s\n", strerror(ferror(stdout)));
|
fprintf(stderr, "unable to write to stdout: %s\n", strerror(ferror(stdout)));
|
||||||
|
@ -871,7 +875,14 @@ int main(int argc, char **argv) {
|
||||||
|
|
||||||
Buf *zig_lib_dir_buf = resolve_zig_lib_dir();
|
Buf *zig_lib_dir_buf = resolve_zig_lib_dir();
|
||||||
|
|
||||||
CodeGen *g = codegen_create(zig_root_source_file, target, out_type, build_mode, zig_lib_dir_buf);
|
Buf *compiler_id;
|
||||||
|
if ((err = get_compiler_id(&compiler_id))) {
|
||||||
|
fprintf(stderr, "Unable to determine compiler id: %s\n", err_str(err));
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
CodeGen *g = codegen_create(zig_root_source_file, target, out_type, build_mode, zig_lib_dir_buf,
|
||||||
|
compiler_id);
|
||||||
codegen_set_out_name(g, buf_out_name);
|
codegen_set_out_name(g, buf_out_name);
|
||||||
codegen_set_lib_version(g, ver_major, ver_minor, ver_patch);
|
codegen_set_lib_version(g, ver_major, ver_minor, ver_patch);
|
||||||
codegen_set_is_test(g, cmd == CmdTest);
|
codegen_set_is_test(g, cmd == CmdTest);
|
||||||
|
|
Loading…
Reference in New Issue