| author | |
| committer | |
| log | 7b3686861f87d006da817db98f7d3b13fada9815 |
| tree | b603b7e34cd3138ebe24f42994500efa5bb13bdd |
| parent | 538c0cd2250e08aad07784355b402cfae6145507 |
| signature |
7 files changed, 30 insertions(+), 22 deletions(-)
BRANCH_TODO+9| ... | @@ -1,5 +1,14 @@ | ... | @@ -1,5 +1,14 @@ |
| 1 | * reimplement @frameSize with Prefix Data | ||
| 2 | * reimplement with function splitting rather than switch | ||
| 3 | * add the `anyframe` type and `anyframe->T` | ||
| 1 | * await | 4 | * await |
| 2 | * await of a non async function | 5 | * await of a non async function |
| 6 | * await in single-threaded mode | ||
| 3 | * async call on a non async function | 7 | * async call on a non async function |
| 8 | * @asyncCall with an async function pointer | ||
| 9 | * cancel | ||
| 10 | * defer and errdefer | ||
| 4 | * safety for resuming when it is awaiting | 11 | * safety for resuming when it is awaiting |
| 5 | * implicit cast of normal function to async function should be allowed when it is inferred to be async | 12 | * implicit cast of normal function to async function should be allowed when it is inferred to be async |
| 13 | * go over the commented out tests | ||
| 14 | * revive std.event.Loop |
src/all_types.hpp-1| ... | @@ -3063,7 +3063,6 @@ struct IrInstructionFrameSizeGen { | ... | @@ -3063,7 +3063,6 @@ struct IrInstructionFrameSizeGen { |
| 3063 | IrInstruction base; | 3063 | IrInstruction base; |
| 3064 | 3064 | ||
| 3065 | IrInstruction *fn; | 3065 | IrInstruction *fn; |
| 3066 | IrInstruction *frame_ptr; | ||
| 3067 | }; | 3066 | }; |
| 3068 | 3067 | ||
| 3069 | enum IrOverflowOp { | 3068 | enum IrOverflowOp { |
src/codegen.cpp+13-8| ... | @@ -4914,13 +4914,16 @@ static LLVMValueRef ir_render_coro_resume(CodeGen *g, IrExecutable *executable, | ... | @@ -4914,13 +4914,16 @@ static LLVMValueRef ir_render_coro_resume(CodeGen *g, IrExecutable *executable, |
| 4914 | return nullptr; | 4914 | return nullptr; |
| 4915 | } | 4915 | } |
| 4916 | 4916 | ||
| 4917 | static LLVMValueRef ir_render_frame_size(CodeGen *g, IrExecutable *executable, IrInstructionFrameSizeGen *instruction) { | 4917 | static LLVMValueRef ir_render_frame_size(CodeGen *g, IrExecutable *executable, |
| 4918 | IrInstructionFrameSizeGen *instruction) | ||
| 4919 | { | ||
| 4920 | LLVMTypeRef usize_llvm_type = g->builtin_types.entry_usize->llvm_type; | ||
| 4921 | LLVMTypeRef ptr_usize_llvm_type = LLVMPointerType(usize_llvm_type, 0); | ||
| 4918 | LLVMValueRef fn_val = ir_llvm_value(g, instruction->fn); | 4922 | LLVMValueRef fn_val = ir_llvm_value(g, instruction->fn); |
| 4919 | LLVMValueRef frame_ptr = ir_llvm_value(g, instruction->frame_ptr); | 4923 | LLVMValueRef casted_fn_val = LLVMBuildBitCast(g->builder, fn_val, ptr_usize_llvm_type, ""); |
| 4920 | LLVMValueRef resume_index_ptr = LLVMBuildStructGEP(g->builder, frame_ptr, coro_resume_index_index, ""); | 4924 | LLVMValueRef negative_one = LLVMConstInt(LLVMInt32Type(), -1, true); |
| 4921 | LLVMValueRef one = LLVMConstInt(g->builtin_types.entry_usize->llvm_type, 1, false); | 4925 | LLVMValueRef prefix_ptr = LLVMBuildInBoundsGEP(g->builder, casted_fn_val, &negative_one, 1, ""); |
| 4922 | LLVMBuildStore(g->builder, one, resume_index_ptr); | 4926 | return LLVMBuildLoad(g->builder, prefix_ptr, ""); |
| 4923 | return ZigLLVMBuildCall(g->builder, fn_val, &frame_ptr, 1, LLVMFastCallConv, ZigLLVM_FnInlineAuto, ""); | ||
| 4924 | } | 4927 | } |
| 4925 | 4928 | ||
| 4926 | static void set_debug_location(CodeGen *g, IrInstruction *instruction) { | 4929 | static void set_debug_location(CodeGen *g, IrInstruction *instruction) { |
| ... | @@ -6409,13 +6412,16 @@ static void do_code_gen(CodeGen *g) { | ... | @@ -6409,13 +6412,16 @@ static void do_code_gen(CodeGen *g) { |
| 6409 | } | 6412 | } |
| 6410 | 6413 | ||
| 6411 | if (is_async) { | 6414 | if (is_async) { |
| 6415 | LLVMTypeRef usize_type_ref = g->builtin_types.entry_usize->llvm_type; | ||
| 6416 | LLVMValueRef size_val = LLVMConstInt(usize_type_ref, fn_table_entry->frame_type->abi_size, false); | ||
| 6417 | ZigLLVMFunctionSetPrefixData(fn_table_entry->llvm_value, size_val); | ||
| 6418 | |||
| 6412 | if (!g->strip_debug_symbols) { | 6419 | if (!g->strip_debug_symbols) { |
| 6413 | AstNode *source_node = fn_table_entry->proto_node; | 6420 | AstNode *source_node = fn_table_entry->proto_node; |
| 6414 | ZigLLVMSetCurrentDebugLocation(g->builder, (int)source_node->line + 1, | 6421 | ZigLLVMSetCurrentDebugLocation(g->builder, (int)source_node->line + 1, |
| 6415 | (int)source_node->column + 1, get_di_scope(g, fn_table_entry->child_scope)); | 6422 | (int)source_node->column + 1, get_di_scope(g, fn_table_entry->child_scope)); |
| 6416 | } | 6423 | } |
| 6417 | IrExecutable *executable = &fn_table_entry->analyzed_executable; | 6424 | IrExecutable *executable = &fn_table_entry->analyzed_executable; |
| 6418 | LLVMTypeRef usize_type_ref = g->builtin_types.entry_usize->llvm_type; | ||
| 6419 | LLVMBasicBlockRef bad_resume_block = LLVMAppendBasicBlock(g->cur_fn_val, "BadResume"); | 6425 | LLVMBasicBlockRef bad_resume_block = LLVMAppendBasicBlock(g->cur_fn_val, "BadResume"); |
| 6420 | LLVMPositionBuilderAtEnd(g->builder, bad_resume_block); | 6426 | LLVMPositionBuilderAtEnd(g->builder, bad_resume_block); |
| 6421 | gen_assertion_scope(g, PanicMsgIdBadResume, fn_table_entry->child_scope); | 6427 | gen_assertion_scope(g, PanicMsgIdBadResume, fn_table_entry->child_scope); |
| ... | @@ -6424,7 +6430,6 @@ static void do_code_gen(CodeGen *g) { | ... | @@ -6424,7 +6430,6 @@ static void do_code_gen(CodeGen *g) { |
| 6424 | LLVMPositionBuilderAtEnd(g->builder, get_size_block); | 6430 | LLVMPositionBuilderAtEnd(g->builder, get_size_block); |
| 6425 | assert(fn_table_entry->frame_type->abi_size != 0); | 6431 | assert(fn_table_entry->frame_type->abi_size != 0); |
| 6426 | assert(fn_table_entry->frame_type->abi_size != SIZE_MAX); | 6432 | assert(fn_table_entry->frame_type->abi_size != SIZE_MAX); |
| 6427 | LLVMValueRef size_val = LLVMConstInt(usize_type_ref, fn_table_entry->frame_type->abi_size, false); | ||
| 6428 | LLVMBuildRet(g->builder, size_val); | 6433 | LLVMBuildRet(g->builder, size_val); |
| 6429 | 6434 | ||
| 6430 | LLVMPositionBuilderAtEnd(g->builder, fn_table_entry->preamble_llvm_block); | 6435 | LLVMPositionBuilderAtEnd(g->builder, fn_table_entry->preamble_llvm_block); |
src/ir.cpp+2-10| ... | @@ -2396,15 +2396,12 @@ static IrInstruction *ir_build_frame_size_src(IrBuilder *irb, Scope *scope, AstN | ... | @@ -2396,15 +2396,12 @@ static IrInstruction *ir_build_frame_size_src(IrBuilder *irb, Scope *scope, AstN |
| 2396 | return &instruction->base; | 2396 | return &instruction->base; |
| 2397 | } | 2397 | } |
| 2398 | 2398 | ||
| 2399 | static IrInstruction *ir_build_frame_size_gen(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *fn, | 2399 | static IrInstruction *ir_build_frame_size_gen(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *fn) |
| 2400 | IrInstruction *frame_ptr) | ||
| 2401 | { | 2400 | { |
| 2402 | IrInstructionFrameSizeGen *instruction = ir_build_instruction<IrInstructionFrameSizeGen>(irb, scope, source_node); | 2401 | IrInstructionFrameSizeGen *instruction = ir_build_instruction<IrInstructionFrameSizeGen>(irb, scope, source_node); |
| 2403 | instruction->fn = fn; | 2402 | instruction->fn = fn; |
| 2404 | instruction->frame_ptr = frame_ptr; | ||
| 2405 | 2403 | ||
| 2406 | ir_ref_instruction(fn, irb->current_basic_block); | 2404 | ir_ref_instruction(fn, irb->current_basic_block); |
| 2407 | ir_ref_instruction(frame_ptr, irb->current_basic_block); | ||
| 2408 | 2405 | ||
| 2409 | return &instruction->base; | 2406 | return &instruction->base; |
| 2410 | } | 2407 | } |
| ... | @@ -21808,13 +21805,8 @@ static IrInstruction *ir_analyze_instruction_frame_size(IrAnalyze *ira, IrInstru | ... | @@ -21808,13 +21805,8 @@ static IrInstruction *ir_analyze_instruction_frame_size(IrAnalyze *ira, IrInstru |
| 21808 | return ira->codegen->invalid_instruction; | 21805 | return ira->codegen->invalid_instruction; |
| 21809 | } | 21806 | } |
| 21810 | 21807 | ||
| 21811 | IrInstruction *frame_ptr = ir_resolve_result(ira, &instruction->base, no_result_loc(), | ||
| 21812 | ira->codegen->builtin_types.entry_frame_header, nullptr, true, false); | ||
| 21813 | if (frame_ptr != nullptr && (type_is_invalid(frame_ptr->value.type) || instr_is_unreachable(frame_ptr))) | ||
| 21814 | return frame_ptr; | ||
| 21815 | |||
| 21816 | IrInstruction *result = ir_build_frame_size_gen(&ira->new_irb, instruction->base.scope, | 21808 | IrInstruction *result = ir_build_frame_size_gen(&ira->new_irb, instruction->base.scope, |
| 21817 | instruction->base.source_node, fn, frame_ptr); | 21809 | instruction->base.source_node, fn); |
| 21818 | result->value.type = ira->codegen->builtin_types.entry_usize; | 21810 | result->value.type = ira->codegen->builtin_types.entry_usize; |
| 21819 | return result; | 21811 | return result; |
| 21820 | } | 21812 | } |
src/ir_print.cpp-2| ... | @@ -925,8 +925,6 @@ static void ir_print_frame_size_src(IrPrint *irp, IrInstructionFrameSizeSrc *ins | ... | @@ -925,8 +925,6 @@ static void ir_print_frame_size_src(IrPrint *irp, IrInstructionFrameSizeSrc *ins |
| 925 | static void ir_print_frame_size_gen(IrPrint *irp, IrInstructionFrameSizeGen *instruction) { | 925 | static void ir_print_frame_size_gen(IrPrint *irp, IrInstructionFrameSizeGen *instruction) { |
| 926 | fprintf(irp->f, "@frameSize("); | 926 | fprintf(irp->f, "@frameSize("); |
| 927 | ir_print_other_instruction(irp, instruction->fn); | 927 | ir_print_other_instruction(irp, instruction->fn); |
| 928 | fprintf(irp->f, ","); | ||
| 929 | ir_print_other_instruction(irp, instruction->frame_ptr); | ||
| 930 | fprintf(irp->f, ")"); | 928 | fprintf(irp->f, ")"); |
| 931 | } | 929 | } |
| 932 | 930 |
src/zig_llvm.cpp+5-1| ... | @@ -899,9 +899,13 @@ LLVMValueRef ZigLLVMBuildAShrExact(LLVMBuilderRef builder, LLVMValueRef LHS, LLV | ... | @@ -899,9 +899,13 @@ LLVMValueRef ZigLLVMBuildAShrExact(LLVMBuilderRef builder, LLVMValueRef LHS, LLV |
| 899 | } | 899 | } |
| 900 | 900 | ||
| 901 | void ZigLLVMSetTailCall(LLVMValueRef Call) { | 901 | void ZigLLVMSetTailCall(LLVMValueRef Call) { |
| 902 | unwrap<CallInst>(Call)->setTailCallKind(CallInst::TCK_MustTail); | 902 | unwrap<CallInst>(Call)->setTailCallKind(CallInst::TCK_MustTail); |
| 903 | } | 903 | } |
| 904 | 904 | ||
| 905 | void ZigLLVMFunctionSetPrefixData(LLVMValueRef function, LLVMValueRef data) { | ||
| 906 | unwrap<Function>(function)->setPrefixData(unwrap<Constant>(data)); | ||
| 907 | } | ||
| 908 | |||
| 905 | 909 | ||
| 906 | class MyOStream: public raw_ostream { | 910 | class MyOStream: public raw_ostream { |
| 907 | public: | 911 | public: |
src/zig_llvm.h+1| ... | @@ -212,6 +212,7 @@ ZIG_EXTERN_C struct ZigLLVMDILocation *ZigLLVMGetDebugLoc(unsigned line, unsigne | ... | @@ -212,6 +212,7 @@ ZIG_EXTERN_C struct ZigLLVMDILocation *ZigLLVMGetDebugLoc(unsigned line, unsigne |
| 212 | 212 | ||
| 213 | ZIG_EXTERN_C void ZigLLVMSetFastMath(LLVMBuilderRef builder_wrapped, bool on_state); | 213 | ZIG_EXTERN_C void ZigLLVMSetFastMath(LLVMBuilderRef builder_wrapped, bool on_state); |
| 214 | ZIG_EXTERN_C void ZigLLVMSetTailCall(LLVMValueRef Call); | 214 | ZIG_EXTERN_C void ZigLLVMSetTailCall(LLVMValueRef Call); |
| 215 | ZIG_EXTERN_C void ZigLLVMFunctionSetPrefixData(LLVMValueRef fn, LLVMValueRef data); | ||
| 215 | 216 | ||
| 216 | ZIG_EXTERN_C void ZigLLVMAddFunctionAttr(LLVMValueRef fn, const char *attr_name, const char *attr_value); | 217 | ZIG_EXTERN_C void ZigLLVMAddFunctionAttr(LLVMValueRef fn, const char *attr_name, const char *attr_value); |
| 217 | ZIG_EXTERN_C void ZigLLVMAddFunctionAttrCold(LLVMValueRef fn); | 218 | ZIG_EXTERN_C void ZigLLVMAddFunctionAttrCold(LLVMValueRef fn); |