Commit d74b8567cf

Andrew Kelley <andrew@ziglang.org>
2019-09-03 03:22:35
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
1 parent 00d82e3
Changed files (3)
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,
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;
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;