authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-02-25 16:29:07-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-02-25 16:29:07-05:00
log0cf327eb17360cddcdfab623db049aca5afd7010
treef84c559f40b1a644de94db9ae7e3e09f402b5c89
parentd0f2eca106f556fe5826d96b08ffdf1be1293915

codegen for coro_suspend instruction

See #727

2 files changed, 29 insertions(+), 1 deletions(-)

src/all_types.hpp+1
......@@ -1614,6 +1614,7 @@ struct CodeGen {
16141614 LLVMValueRef coro_alloc_fn_val;
16151615 LLVMValueRef coro_size_fn_val;
16161616 LLVMValueRef coro_begin_fn_val;
1617 LLVMValueRef coro_suspend_fn_val;
16171618 bool error_during_imports;
16181619
16191620 const char **clang_argv;
src/codegen.cpp+28-1
......@@ -1003,6 +1003,22 @@ static LLVMValueRef get_coro_begin_fn_val(CodeGen *g) {
10031003 return g->coro_begin_fn_val;
10041004}
10051005
1006static LLVMValueRef get_coro_suspend_fn_val(CodeGen *g) {
1007 if (g->coro_suspend_fn_val)
1008 return g->coro_suspend_fn_val;
1009
1010 LLVMTypeRef param_types[] = {
1011 ZigLLVMTokenTypeInContext(LLVMGetGlobalContext()),
1012 LLVMInt1Type(),
1013 };
1014 LLVMTypeRef fn_type = LLVMFunctionType(LLVMInt8Type(), param_types, 2, false);
1015 Buf *name = buf_sprintf("llvm.coro.suspend");
1016 g->coro_suspend_fn_val = LLVMAddFunction(g->module, buf_ptr(name), fn_type);
1017 assert(LLVMGetIntrinsicID(g->coro_suspend_fn_val));
1018
1019 return g->coro_suspend_fn_val;
1020}
1021
10061022static LLVMValueRef get_return_address_fn_val(CodeGen *g) {
10071023 if (g->return_address_fn_val)
10081024 return g->return_address_fn_val;
......@@ -3854,7 +3870,18 @@ static LLVMValueRef ir_render_coro_alloc_fail(CodeGen *g, IrExecutable *executab
38543870}
38553871
38563872static LLVMValueRef ir_render_coro_suspend(CodeGen *g, IrExecutable *executable, IrInstructionCoroSuspend *instruction) {
3857 zig_panic("TODO ir_render_coro_suspend");
3873 LLVMValueRef save_point;
3874 if (instruction->save_point == nullptr) {
3875 save_point = LLVMConstNull(ZigLLVMTokenTypeInContext(LLVMGetGlobalContext()));
3876 } else {
3877 save_point = ir_llvm_value(g, instruction->save_point);
3878 }
3879 LLVMValueRef is_final = ir_llvm_value(g, instruction->is_final);
3880 LLVMValueRef params[] = {
3881 save_point,
3882 is_final,
3883 };
3884 return LLVMBuildCall(g->builder, get_coro_suspend_fn_val(g), params, 2, "");
38583885}
38593886
38603887static LLVMValueRef ir_render_coro_end(CodeGen *g, IrExecutable *executable, IrInstructionCoroEnd *instruction) {