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;
36703670static const size_t coro_awaiter_index = 2;
36713671static 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.
3674static const size_t coro_extra_resume_block_count = 2;
3673// one for the Entry block, resume blocks are indexed after that.
3674static const size_t coro_extra_resume_block_count = 1;
36753675
36763676// TODO call graph analysis to find out what this number needs to be for every function
36773677// 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) {
72547254 ZigList<ZigLLVMDIType *> param_di_types = {};
72557255 ZigType *gen_return_type;
72567256 if (is_async) {
7257 gen_return_type = g->builtin_types.entry_usize;
7257 gen_return_type = g->builtin_types.entry_void;
72587258 param_di_types.append(get_llvm_di_type(g, gen_return_type));
72597259 } else if (!type_has_bits(fn_type_id->return_type)) {
72607260 gen_return_type = g->builtin_types.entry_void;
......@@ -7354,7 +7354,7 @@ void resolve_llvm_types_fn(CodeGen *g, ZigFn *fn) {
73547354 return;
73557355 }
73567356
7357 ZigType *gen_return_type = g->builtin_types.entry_usize;
7357 ZigType *gen_return_type = g->builtin_types.entry_void;
73587358 ZigList<ZigLLVMDIType *> param_di_types = {};
73597359 // first "parameter" is return value
73607360 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
19951995 LLVMBuildStore(g->builder, new_resume_index, resume_index_ptr);
19961996 }
19971997
1998 LLVMBuildRet(g->builder, LLVMGetUndef(g->builtin_types.entry_usize->llvm_type));
1998 LLVMBuildRetVoid(g->builder);
19991999 return nullptr;
20002000 }
20012001 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
34383438
34393439 LLVMValueRef call_inst = ZigLLVMBuildCall(g->builder, fn_val, &frame_result_loc, 1, llvm_cc, fn_inline, "");
34403440 ZigLLVMSetTailCall(call_inst);
3441 LLVMBuildRet(g->builder, call_inst);
3441 LLVMBuildRetVoid(g->builder);
34423442
34433443 LLVMPositionBuilderAtEnd(g->builder, instruction->resume_block->llvm_block);
34443444 return nullptr;
......@@ -4898,7 +4898,7 @@ static LLVMValueRef ir_render_suspend_begin(CodeGen *g, IrExecutable *executable
48984898static LLVMValueRef ir_render_suspend_br(CodeGen *g, IrExecutable *executable,
48994899 IrInstructionSuspendBr *instruction)
49004900{
4901 LLVMBuildRet(g->builder, LLVMGetUndef(g->builtin_types.entry_usize->llvm_type));
4901 LLVMBuildRetVoid(g->builder);
49024902 return nullptr;
49034903}
49044904
......@@ -6426,27 +6426,17 @@ static void do_code_gen(CodeGen *g) {
64266426 LLVMPositionBuilderAtEnd(g->builder, bad_resume_block);
64276427 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
64356429 LLVMPositionBuilderAtEnd(g->builder, fn_table_entry->preamble_llvm_block);
64366430 LLVMValueRef resume_index_ptr = LLVMBuildStructGEP(g->builder, g->cur_ret_ptr,
64376431 coro_resume_index_index, "");
64386432 LLVMValueRef resume_index = LLVMBuildLoad(g->builder, resume_index_ptr, "");
64396433 // +1 - index 0 is reserved for the entry block
6440 // +1 - index 1 is reserved for getting the size.
64416434 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
64446437 LLVMValueRef zero = LLVMConstNull(usize_type_ref);
64456438 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
64506440 for (size_t resume_i = 0; resume_i < fn_table_entry->resume_blocks.length; resume_i += 1) {
64516441 IrBasicBlock *resume_block = fn_table_entry->resume_blocks.at(resume_i);
64526442 LLVMValueRef case_value = LLVMConstInt(usize_type_ref, resume_block->resume_index, false);