Merge pull request #925 from alexnask/release_small

Added ReleaseSmall mode.
master
Andrew Kelley 2018-04-15 21:57:26 -04:00 committed by GitHub
commit 88724217dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 52 additions and 15 deletions

View File

@ -749,6 +749,10 @@ fn genHtml(allocator: &mem.Allocator, tokenizer: &Tokenizer, toc: &Toc, out: var
try build_args.append("--release-fast"); try build_args.append("--release-fast");
try out.print(" --release-fast"); try out.print(" --release-fast");
}, },
builtin.Mode.ReleaseSmall => {
try build_args.append("--release-small");
try out.print(" --release-small");
},
} }
for (code.link_objects) |link_object| { for (code.link_objects) |link_object| {
const name_with_ext = try std.fmt.allocPrint(allocator, "{}{}", link_object, obj_ext); const name_with_ext = try std.fmt.allocPrint(allocator, "{}{}", link_object, obj_ext);
@ -810,6 +814,10 @@ fn genHtml(allocator: &mem.Allocator, tokenizer: &Tokenizer, toc: &Toc, out: var
try test_args.append("--release-fast"); try test_args.append("--release-fast");
try out.print(" --release-fast"); try out.print(" --release-fast");
}, },
builtin.Mode.ReleaseSmall => {
try test_args.append("--release-small");
try out.print(" --release-small");
},
} }
if (code.target_windows) { if (code.target_windows) {
try test_args.appendSlice([][]const u8{ try test_args.appendSlice([][]const u8{
@ -840,6 +848,10 @@ fn genHtml(allocator: &mem.Allocator, tokenizer: &Tokenizer, toc: &Toc, out: var
try test_args.append("--release-fast"); try test_args.append("--release-fast");
try out.print(" --release-fast"); try out.print(" --release-fast");
}, },
builtin.Mode.ReleaseSmall => {
try test_args.append("--release-small");
try out.print(" --release-small");
},
} }
const result = try os.ChildProcess.exec(allocator, test_args.toSliceConst(), null, null, max_doc_file_size); const result = try os.ChildProcess.exec(allocator, test_args.toSliceConst(), null, null, max_doc_file_size);
switch (result.term) { switch (result.term) {
@ -874,6 +886,7 @@ fn genHtml(allocator: &mem.Allocator, tokenizer: &Tokenizer, toc: &Toc, out: var
builtin.Mode.Debug => {}, builtin.Mode.Debug => {},
builtin.Mode.ReleaseSafe => try test_args.append("--release-safe"), builtin.Mode.ReleaseSafe => try test_args.append("--release-safe"),
builtin.Mode.ReleaseFast => try test_args.append("--release-fast"), builtin.Mode.ReleaseFast => try test_args.append("--release-fast"),
builtin.Mode.ReleaseSmall => try test_args.append("--release-small"),
} }
const result = try os.ChildProcess.exec(allocator, test_args.toSliceConst(), null, null, max_doc_file_size); const result = try os.ChildProcess.exec(allocator, test_args.toSliceConst(), null, null, max_doc_file_size);
@ -927,6 +940,12 @@ fn genHtml(allocator: &mem.Allocator, tokenizer: &Tokenizer, toc: &Toc, out: var
try out.print(" --release-fast"); try out.print(" --release-fast");
} }
}, },
builtin.Mode.ReleaseSmall => {
try build_args.append("--release-small");
if (!code.is_inline) {
try out.print(" --release-small");
}
},
} }
if (maybe_error_match) |error_match| { if (maybe_error_match) |error_match| {

View File

@ -1457,6 +1457,7 @@ enum BuildMode {
BuildModeDebug, BuildModeDebug,
BuildModeFastRelease, BuildModeFastRelease,
BuildModeSafeRelease, BuildModeSafeRelease,
BuildModeSmallRelease,
}; };
enum EmitFileType { enum EmitFileType {

View File

@ -512,7 +512,9 @@ static LLVMValueRef fn_llvm_value(CodeGen *g, FnTableEntry *fn_table_entry) {
} }
if (fn_table_entry->body_node != nullptr) { if (fn_table_entry->body_node != nullptr) {
bool want_fn_safety = g->build_mode != BuildModeFastRelease && !fn_table_entry->def_scope->safety_off; bool want_fn_safety = g->build_mode != BuildModeFastRelease &&
g->build_mode != BuildModeSmallRelease &&
!fn_table_entry->def_scope->safety_off;
if (want_fn_safety) { if (want_fn_safety) {
if (g->libc_link_lib != nullptr) { if (g->libc_link_lib != nullptr) {
addLLVMFnAttr(fn_table_entry->llvm_value, "sspstrong"); addLLVMFnAttr(fn_table_entry->llvm_value, "sspstrong");
@ -817,7 +819,7 @@ static bool ir_want_fast_math(CodeGen *g, IrInstruction *instruction) {
} }
static bool ir_want_runtime_safety(CodeGen *g, IrInstruction *instruction) { static bool ir_want_runtime_safety(CodeGen *g, IrInstruction *instruction) {
if (g->build_mode == BuildModeFastRelease) if (g->build_mode == BuildModeFastRelease || g->build_mode == BuildModeSmallRelease)
return false; return false;
// TODO memoize // TODO memoize
@ -5747,10 +5749,12 @@ static void do_code_gen(CodeGen *g) {
os_path_join(g->cache_dir, o_basename, output_path); os_path_join(g->cache_dir, o_basename, output_path);
ensure_cache_dir(g); ensure_cache_dir(g);
bool is_small = g->build_mode == BuildModeSmallRelease;
switch (g->emit_file_type) { switch (g->emit_file_type) {
case EmitFileTypeBinary: case EmitFileTypeBinary:
if (ZigLLVMTargetMachineEmitToFile(g->target_machine, g->module, buf_ptr(output_path), if (ZigLLVMTargetMachineEmitToFile(g->target_machine, g->module, buf_ptr(output_path),
ZigLLVM_EmitBinary, &err_msg, g->build_mode == BuildModeDebug)) ZigLLVM_EmitBinary, &err_msg, g->build_mode == BuildModeDebug, is_small))
{ {
zig_panic("unable to write object file %s: %s", buf_ptr(output_path), err_msg); zig_panic("unable to write object file %s: %s", buf_ptr(output_path), err_msg);
} }
@ -5760,7 +5764,7 @@ static void do_code_gen(CodeGen *g) {
case EmitFileTypeAssembly: case EmitFileTypeAssembly:
if (ZigLLVMTargetMachineEmitToFile(g->target_machine, g->module, buf_ptr(output_path), if (ZigLLVMTargetMachineEmitToFile(g->target_machine, g->module, buf_ptr(output_path),
ZigLLVM_EmitAssembly, &err_msg, g->build_mode == BuildModeDebug)) ZigLLVM_EmitAssembly, &err_msg, g->build_mode == BuildModeDebug, is_small))
{ {
zig_panic("unable to write assembly file %s: %s", buf_ptr(output_path), err_msg); zig_panic("unable to write assembly file %s: %s", buf_ptr(output_path), err_msg);
} }
@ -5769,7 +5773,7 @@ static void do_code_gen(CodeGen *g) {
case EmitFileTypeLLVMIr: case EmitFileTypeLLVMIr:
if (ZigLLVMTargetMachineEmitToFile(g->target_machine, g->module, buf_ptr(output_path), if (ZigLLVMTargetMachineEmitToFile(g->target_machine, g->module, buf_ptr(output_path),
ZigLLVM_EmitLLVMIr, &err_msg, g->build_mode == BuildModeDebug)) ZigLLVM_EmitLLVMIr, &err_msg, g->build_mode == BuildModeDebug, is_small))
{ {
zig_panic("unable to write llvm-ir file %s: %s", buf_ptr(output_path), err_msg); zig_panic("unable to write llvm-ir file %s: %s", buf_ptr(output_path), err_msg);
} }
@ -6160,6 +6164,7 @@ static const char *build_mode_to_str(BuildMode build_mode) {
case BuildModeDebug: return "Mode.Debug"; case BuildModeDebug: return "Mode.Debug";
case BuildModeSafeRelease: return "Mode.ReleaseSafe"; case BuildModeSafeRelease: return "Mode.ReleaseSafe";
case BuildModeFastRelease: return "Mode.ReleaseFast"; case BuildModeFastRelease: return "Mode.ReleaseFast";
case BuildModeSmallRelease: return "Mode.ReleaseSmall";
} }
zig_unreachable(); zig_unreachable();
} }
@ -6300,6 +6305,7 @@ static void define_builtin_compile_vars(CodeGen *g) {
" Debug,\n" " Debug,\n"
" ReleaseSafe,\n" " ReleaseSafe,\n"
" ReleaseFast,\n" " ReleaseFast,\n"
" ReleaseSmall,\n"
"};\n\n"); "};\n\n");
} }
{ {
@ -6471,7 +6477,7 @@ static void init(CodeGen *g) {
} }
} }
g->have_err_ret_tracing = g->build_mode != BuildModeFastRelease; g->have_err_ret_tracing = g->build_mode != BuildModeFastRelease && g->build_mode != BuildModeSmallRelease;
define_builtin_fns(g); define_builtin_fns(g);
define_builtin_compile_vars(g); define_builtin_compile_vars(g);

View File

@ -43,6 +43,7 @@ static int usage(const char *arg0) {
" --pkg-end pop current pkg\n" " --pkg-end pop current pkg\n"
" --release-fast build with optimizations on and safety off\n" " --release-fast build with optimizations on and safety off\n"
" --release-safe build with optimizations on and safety on\n" " --release-safe build with optimizations on and safety on\n"
" --release-small build with size optimizations on and safety off\n"
" --static output will be statically linked\n" " --static output will be statically linked\n"
" --strip exclude debug symbols\n" " --strip exclude debug symbols\n"
" --target-arch [name] specify target architecture\n" " --target-arch [name] specify target architecture\n"
@ -482,6 +483,8 @@ int main(int argc, char **argv) {
build_mode = BuildModeFastRelease; build_mode = BuildModeFastRelease;
} else if (strcmp(arg, "--release-safe") == 0) { } else if (strcmp(arg, "--release-safe") == 0) {
build_mode = BuildModeSafeRelease; build_mode = BuildModeSafeRelease;
} else if (strcmp(arg, "--release-small") == 0) {
build_mode = BuildModeSmallRelease;
} else if (strcmp(arg, "--strip") == 0) { } else if (strcmp(arg, "--strip") == 0) {
strip = true; strip = true;
} else if (strcmp(arg, "--static") == 0) { } else if (strcmp(arg, "--static") == 0) {

View File

@ -81,7 +81,7 @@ static const bool assertions_on = false;
#endif #endif
bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machine_ref, LLVMModuleRef module_ref, bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machine_ref, LLVMModuleRef module_ref,
const char *filename, ZigLLVM_EmitOutputType output_type, char **error_message, bool is_debug) const char *filename, ZigLLVM_EmitOutputType output_type, char **error_message, bool is_debug, bool is_small)
{ {
std::error_code EC; std::error_code EC;
raw_fd_ostream dest(filename, EC, sys::fs::F_None); raw_fd_ostream dest(filename, EC, sys::fs::F_None);
@ -100,7 +100,7 @@ bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machine_ref, LLVMM
return true; return true;
} }
PMBuilder->OptLevel = target_machine->getOptLevel(); PMBuilder->OptLevel = target_machine->getOptLevel();
PMBuilder->SizeLevel = 0; PMBuilder->SizeLevel = is_small ? 2 : 0;
PMBuilder->DisableTailCalls = is_debug; PMBuilder->DisableTailCalls = is_debug;
PMBuilder->DisableUnitAtATime = is_debug; PMBuilder->DisableUnitAtATime = is_debug;

View File

@ -52,7 +52,7 @@ enum ZigLLVM_EmitOutputType {
}; };
ZIG_EXTERN_C bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machine_ref, LLVMModuleRef module_ref, ZIG_EXTERN_C bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machine_ref, LLVMModuleRef module_ref,
const char *filename, enum ZigLLVM_EmitOutputType output_type, char **error_message, bool is_debug); const char *filename, enum ZigLLVM_EmitOutputType output_type, char **error_message, bool is_debug, bool is_small);
ZIG_EXTERN_C LLVMTypeRef ZigLLVMTokenTypeInContext(LLVMContextRef context_ref); ZIG_EXTERN_C LLVMTypeRef ZigLLVMTokenTypeInContext(LLVMContextRef context_ref);

View File

@ -426,15 +426,18 @@ pub const Builder = struct {
const release_safe = self.option(bool, "release-safe", "optimizations on and safety on") ?? false; const release_safe = self.option(bool, "release-safe", "optimizations on and safety on") ?? false;
const release_fast = self.option(bool, "release-fast", "optimizations on and safety off") ?? false; const release_fast = self.option(bool, "release-fast", "optimizations on and safety off") ?? false;
const release_small = self.option(bool, "release-small", "size optimizations on and safety off") ?? false;
const mode = if (release_safe and !release_fast) const mode = if (release_safe and !release_fast and !release_small)
builtin.Mode.ReleaseSafe builtin.Mode.ReleaseSafe
else if (release_fast and !release_safe) else if (release_fast and !release_safe and !release_small)
builtin.Mode.ReleaseFast builtin.Mode.ReleaseFast
else if (!release_fast and !release_safe) else if (release_small and !release_fast and !release_safe)
builtin.Mode.ReleaseSmall
else if (!release_fast and !release_safe and !release_small)
builtin.Mode.Debug builtin.Mode.Debug
else x: { else x: {
warn("Both -Drelease-safe and -Drelease-fast specified"); warn("Multiple release modes (of -Drelease-safe, -Drelease-fast and -Drelease-small)");
self.markInvalidUserInput(); self.markInvalidUserInput();
break :x builtin.Mode.Debug; break :x builtin.Mode.Debug;
}; };
@ -1229,6 +1232,7 @@ pub const LibExeObjStep = struct {
builtin.Mode.Debug => {}, builtin.Mode.Debug => {},
builtin.Mode.ReleaseSafe => zig_args.append("--release-safe") catch unreachable, builtin.Mode.ReleaseSafe => zig_args.append("--release-safe") catch unreachable,
builtin.Mode.ReleaseFast => zig_args.append("--release-fast") catch unreachable, builtin.Mode.ReleaseFast => zig_args.append("--release-fast") catch unreachable,
builtin.Mode.ReleaseSmall => zig_args.append("--release-small") catch unreachable,
} }
zig_args.append("--cache-dir") catch unreachable; zig_args.append("--cache-dir") catch unreachable;
@ -1369,7 +1373,7 @@ pub const LibExeObjStep = struct {
args.append("ssp-buffer-size=4") catch unreachable; args.append("ssp-buffer-size=4") catch unreachable;
} }
}, },
builtin.Mode.ReleaseFast => { builtin.Mode.ReleaseFast, builtin.Mode.ReleaseSmall => {
args.append("-O2") catch unreachable; args.append("-O2") catch unreachable;
args.append("-fno-stack-protector") catch unreachable; args.append("-fno-stack-protector") catch unreachable;
}, },
@ -1706,6 +1710,7 @@ pub const TestStep = struct {
builtin.Mode.Debug => {}, builtin.Mode.Debug => {},
builtin.Mode.ReleaseSafe => try zig_args.append("--release-safe"), builtin.Mode.ReleaseSafe => try zig_args.append("--release-safe"),
builtin.Mode.ReleaseFast => try zig_args.append("--release-fast"), builtin.Mode.ReleaseFast => try zig_args.append("--release-fast"),
builtin.Mode.ReleaseSmall => try zig_args.append("--release-small"),
} }
switch (self.target) { switch (self.target) {

View File

@ -54,7 +54,9 @@ export fn memmove(dest: ?&u8, src: ?&const u8, n: usize) ?&u8 {
} }
comptime { comptime {
if (builtin.mode != builtin.Mode.ReleaseFast and builtin.os != builtin.Os.windows) { if (builtin.mode != builtin.Mode.ReleaseFast and
builtin.mode != builtin.Mode.ReleaseSmall and
builtin.os != builtin.Os.windows) {
@export("__stack_chk_fail", __stack_chk_fail, builtin.GlobalLinkage.Strong); @export("__stack_chk_fail", __stack_chk_fail, builtin.GlobalLinkage.Strong);
} }
if (builtin.os == builtin.Os.linux and builtin.arch == builtin.Arch.x86_64) { if (builtin.os == builtin.Os.linux and builtin.arch == builtin.Arch.x86_64) {

View File

@ -583,6 +583,7 @@ pub const CompileErrorContext = struct {
Mode.Debug => {}, Mode.Debug => {},
Mode.ReleaseSafe => zig_args.append("--release-safe") catch unreachable, Mode.ReleaseSafe => zig_args.append("--release-safe") catch unreachable,
Mode.ReleaseFast => zig_args.append("--release-fast") catch unreachable, Mode.ReleaseFast => zig_args.append("--release-fast") catch unreachable,
Mode.ReleaseSmall => zig_args.append("--release-small") catch unreachable,
} }
warn("Test {}/{} {}...", self.test_index+1, self.context.test_index, self.name); warn("Test {}/{} {}...", self.test_index+1, self.context.test_index, self.name);