authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-07-26 17:07:19-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-07-26 17:07:19-04:00
log018a89c7a1b2763a50375f6d6d168dfa1f877f6a
tree7c7b11d25b445f23fb0925ae811fd84e07e0897e
parent7b3686861f87d006da817db98f7d3b13fada9815
signature Commit is signed but in an unrecognized format.

async functions return void, no more GetSize resume block


3 files changed, 8 insertions(+), 18 deletions(-)

src/all_types.hpp+2-2
...@@ -3670,8 +3670,8 @@ static const size_t coro_fn_ptr_index = 1;...@@ -3670,8 +3670,8 @@ static const size_t coro_fn_ptr_index = 1;
3670static const size_t coro_awaiter_index = 2;3670static const size_t coro_awaiter_index = 2;
3671static const size_t coro_arg_start = 3;3671static const size_t coro_arg_start = 3;
36723672
3673// one for the GetSize block, one for the Entry block, resume blocks are indexed after that.3673// one for the Entry block, resume blocks are indexed after that.
3674static const size_t coro_extra_resume_block_count = 2;3674static const size_t coro_extra_resume_block_count = 1;
36753675
3676// TODO call graph analysis to find out what this number needs to be for every function3676// TODO call graph analysis to find out what this number needs to be for every function
3677// MUST BE A POWER OF TWO.3677// MUST BE A POWER OF TWO.
src/analyze.cpp+2-2
...@@ -7254,7 +7254,7 @@ static void resolve_llvm_types_fn_type(CodeGen *g, ZigType *fn_type) {...@@ -7254,7 +7254,7 @@ static void resolve_llvm_types_fn_type(CodeGen *g, ZigType *fn_type) {
7254 ZigList<ZigLLVMDIType *> param_di_types = {};7254 ZigList<ZigLLVMDIType *> param_di_types = {};
7255 ZigType *gen_return_type;7255 ZigType *gen_return_type;
7256 if (is_async) {7256 if (is_async) {
7257 gen_return_type = g->builtin_types.entry_usize;7257 gen_return_type = g->builtin_types.entry_void;
7258 param_di_types.append(get_llvm_di_type(g, gen_return_type));7258 param_di_types.append(get_llvm_di_type(g, gen_return_type));
7259 } else if (!type_has_bits(fn_type_id->return_type)) {7259 } else if (!type_has_bits(fn_type_id->return_type)) {
7260 gen_return_type = g->builtin_types.entry_void;7260 gen_return_type = g->builtin_types.entry_void;
...@@ -7354,7 +7354,7 @@ void resolve_llvm_types_fn(CodeGen *g, ZigFn *fn) {...@@ -7354,7 +7354,7 @@ void resolve_llvm_types_fn(CodeGen *g, ZigFn *fn) {
7354 return;7354 return;
7355 }7355 }
73567356
7357 ZigType *gen_return_type = g->builtin_types.entry_usize;7357 ZigType *gen_return_type = g->builtin_types.entry_void;
7358 ZigList<ZigLLVMDIType *> param_di_types = {};7358 ZigList<ZigLLVMDIType *> param_di_types = {};
7359 // first "parameter" is return value7359 // first "parameter" is return value
7360 param_di_types.append(get_llvm_di_type(g, gen_return_type));7360 param_di_types.append(get_llvm_di_type(g, gen_return_type));
src/codegen.cpp+4-14
...@@ -1995,7 +1995,7 @@ static LLVMValueRef ir_render_return(CodeGen *g, IrExecutable *executable, IrIns...@@ -1995,7 +1995,7 @@ static LLVMValueRef ir_render_return(CodeGen *g, IrExecutable *executable, IrIns
1995 LLVMBuildStore(g->builder, new_resume_index, resume_index_ptr);1995 LLVMBuildStore(g->builder, new_resume_index, resume_index_ptr);
1996 }1996 }
19971997
1998 LLVMBuildRet(g->builder, LLVMGetUndef(g->builtin_types.entry_usize->llvm_type));1998 LLVMBuildRetVoid(g->builder);
1999 return nullptr;1999 return nullptr;
2000 }2000 }
2001 if (want_first_arg_sret(g, &g->cur_fn->type_entry->data.fn.fn_type_id)) {2001 if (want_first_arg_sret(g, &g->cur_fn->type_entry->data.fn.fn_type_id)) {
...@@ -3438,7 +3438,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr...@@ -3438,7 +3438,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr
34383438
3439 LLVMValueRef call_inst = ZigLLVMBuildCall(g->builder, fn_val, &frame_result_loc, 1, llvm_cc, fn_inline, "");3439 LLVMValueRef call_inst = ZigLLVMBuildCall(g->builder, fn_val, &frame_result_loc, 1, llvm_cc, fn_inline, "");
3440 ZigLLVMSetTailCall(call_inst);3440 ZigLLVMSetTailCall(call_inst);
3441 LLVMBuildRet(g->builder, call_inst);3441 LLVMBuildRetVoid(g->builder);
34423442
3443 LLVMPositionBuilderAtEnd(g->builder, instruction->resume_block->llvm_block);3443 LLVMPositionBuilderAtEnd(g->builder, instruction->resume_block->llvm_block);
3444 return nullptr;3444 return nullptr;
...@@ -4898,7 +4898,7 @@ static LLVMValueRef ir_render_suspend_begin(CodeGen *g, IrExecutable *executable...@@ -4898,7 +4898,7 @@ static LLVMValueRef ir_render_suspend_begin(CodeGen *g, IrExecutable *executable
4898static LLVMValueRef ir_render_suspend_br(CodeGen *g, IrExecutable *executable,4898static LLVMValueRef ir_render_suspend_br(CodeGen *g, IrExecutable *executable,
4899 IrInstructionSuspendBr *instruction)4899 IrInstructionSuspendBr *instruction)
4900{4900{
4901 LLVMBuildRet(g->builder, LLVMGetUndef(g->builtin_types.entry_usize->llvm_type));4901 LLVMBuildRetVoid(g->builder);
4902 return nullptr;4902 return nullptr;
4903}4903}
49044904
...@@ -6426,27 +6426,17 @@ static void do_code_gen(CodeGen *g) {...@@ -6426,27 +6426,17 @@ static void do_code_gen(CodeGen *g) {
6426 LLVMPositionBuilderAtEnd(g->builder, bad_resume_block);6426 LLVMPositionBuilderAtEnd(g->builder, bad_resume_block);
6427 gen_assertion_scope(g, PanicMsgIdBadResume, fn_table_entry->child_scope);6427 gen_assertion_scope(g, PanicMsgIdBadResume, fn_table_entry->child_scope);
64286428
6429 LLVMBasicBlockRef get_size_block = LLVMAppendBasicBlock(g->cur_fn_val, "GetSize");
6430 LLVMPositionBuilderAtEnd(g->builder, get_size_block);
6431 assert(fn_table_entry->frame_type->abi_size != 0);
6432 assert(fn_table_entry->frame_type->abi_size != SIZE_MAX);
6433 LLVMBuildRet(g->builder, size_val);
6434
6435 LLVMPositionBuilderAtEnd(g->builder, fn_table_entry->preamble_llvm_block);6429 LLVMPositionBuilderAtEnd(g->builder, fn_table_entry->preamble_llvm_block);
6436 LLVMValueRef resume_index_ptr = LLVMBuildStructGEP(g->builder, g->cur_ret_ptr,6430 LLVMValueRef resume_index_ptr = LLVMBuildStructGEP(g->builder, g->cur_ret_ptr,
6437 coro_resume_index_index, "");6431 coro_resume_index_index, "");
6438 LLVMValueRef resume_index = LLVMBuildLoad(g->builder, resume_index_ptr, "");6432 LLVMValueRef resume_index = LLVMBuildLoad(g->builder, resume_index_ptr, "");
6439 // +1 - index 0 is reserved for the entry block6433 // +1 - index 0 is reserved for the entry block
6440 // +1 - index 1 is reserved for getting the size.
6441 LLVMValueRef switch_instr = LLVMBuildSwitch(g->builder, resume_index, bad_resume_block,6434 LLVMValueRef switch_instr = LLVMBuildSwitch(g->builder, resume_index, bad_resume_block,
6442 fn_table_entry->resume_blocks.length + 2);6435 fn_table_entry->resume_blocks.length + 1);
64436436
6444 LLVMValueRef zero = LLVMConstNull(usize_type_ref);6437 LLVMValueRef zero = LLVMConstNull(usize_type_ref);
6445 LLVMAddCase(switch_instr, zero, executable->basic_block_list.at(0)->llvm_block);6438 LLVMAddCase(switch_instr, zero, executable->basic_block_list.at(0)->llvm_block);
64466439
6447 LLVMValueRef one = LLVMConstInt(usize_type_ref, 1, false);
6448 LLVMAddCase(switch_instr, one, get_size_block);
6449
6450 for (size_t resume_i = 0; resume_i < fn_table_entry->resume_blocks.length; resume_i += 1) {6440 for (size_t resume_i = 0; resume_i < fn_table_entry->resume_blocks.length; resume_i += 1) {
6451 IrBasicBlock *resume_block = fn_table_entry->resume_blocks.at(resume_i);6441 IrBasicBlock *resume_block = fn_table_entry->resume_blocks.at(resume_i);
6452 LLVMValueRef case_value = LLVMConstInt(usize_type_ref, resume_block->resume_index, false);6442 LLVMValueRef case_value = LLVMConstInt(usize_type_ref, resume_block->resume_index, false);