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
This commit is contained in:
Andrew Kelley 2019-09-02 21:22:35 -04:00
parent 00d82e34df
commit d74b8567cf
No known key found for this signature in database
GPG Key ID: 7C5F548F728501A9
3 changed files with 8 additions and 1 deletions

View File

@ -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,

View File

@ -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;

View File

@ -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;