commit d74b8567cf6a81550831a9ea02f2cebcb4db9846 (tree)
parent 00d82e34df92c181d20064c0c2f80feaba9dab03
Author: Andrew Kelley <andrew@ziglang.org>
Date: Mon, 2 Sep 2019 21:22:35 -0400
omit prefix data for async functions sometimes
When `@frameSize` is never called, and `@asyncCall` on a runtime-known
pointer is never used, no prefix data for async functions is needed.
Related: #3160
Diffstat:
3 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/src/all_types.hpp b/src/all_types.hpp
@@ -1989,6 +1989,7 @@ struct CodeGen {
bool system_linker_hack;
bool reported_bad_link_libc_error;
bool is_dynamic; // shared library rather than static library. dynamic musl rather than static musl.
+ bool need_frame_size_prefix_data;
//////////////////////////// Participates in Input Parameter Cache Hash
/////// Note: there is a separate cache hash for builtin.zig, when adding fields,
diff --git a/src/codegen.cpp b/src/codegen.cpp
@@ -3775,6 +3775,7 @@ static void render_async_var_decls(CodeGen *g, Scope *scope) {
}
static LLVMValueRef gen_frame_size(CodeGen *g, LLVMValueRef fn_val) {
+ assert(g->need_frame_size_prefix_data);
LLVMTypeRef usize_llvm_type = g->builtin_types.entry_usize->llvm_type;
LLVMTypeRef ptr_usize_llvm_type = LLVMPointerType(usize_llvm_type, 0);
LLVMValueRef casted_fn_val = LLVMBuildBitCast(g->builder, fn_val, ptr_usize_llvm_type, "");
@@ -7208,7 +7209,9 @@ static void do_code_gen(CodeGen *g) {
LLVMTypeRef usize_type_ref = g->builtin_types.entry_usize->llvm_type;
LLVMValueRef size_val = LLVMConstInt(usize_type_ref, fn_table_entry->frame_type->abi_size, false);
- ZigLLVMFunctionSetPrefixData(fn_table_entry->llvm_value, size_val);
+ if (g->need_frame_size_prefix_data) {
+ ZigLLVMFunctionSetPrefixData(fn_table_entry->llvm_value, size_val);
+ }
if (!g->strip_debug_symbols) {
AstNode *source_node = fn_table_entry->proto_node;
diff --git a/src/ir.cpp b/src/ir.cpp
@@ -15671,6 +15671,7 @@ static IrInstruction *analyze_casted_new_stack(IrAnalyze *ira, IrInstructionCall
ZigType *u8_ptr = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8,
false, false, PtrLenUnknown, target_fn_align(ira->codegen->zig_target), 0, 0, false);
ZigType *u8_slice = get_slice_type(ira->codegen, u8_ptr);
+ ira->codegen->need_frame_size_prefix_data = true;
return ir_implicit_cast(ira, new_stack, u8_slice);
}
}
@@ -22533,6 +22534,8 @@ static IrInstruction *ir_analyze_instruction_frame_size(IrAnalyze *ira, IrInstru
return ira->codegen->invalid_instruction;
}
+ ira->codegen->need_frame_size_prefix_data = true;
+
IrInstruction *result = ir_build_frame_size_gen(&ira->new_irb, instruction->base.scope,
instruction->base.source_node, fn);
result->value.type = ira->codegen->builtin_types.entry_usize;