authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-02-25 16:46:01-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-02-25 16:46:01-05:00
log4eac75914bcdf9648518d1837f48e07e35744dc1
treef8f10ac027c164e5333f04801b1bbdc47331cb7b
parentd2d2ba10e9688e6760e75290a29dc055d04a0296

codegen for coro_free instruction

See #727

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

src/all_types.hpp+1
...@@ -1616,6 +1616,7 @@ struct CodeGen {...@@ -1616,6 +1616,7 @@ struct CodeGen {
1616 LLVMValueRef coro_begin_fn_val;1616 LLVMValueRef coro_begin_fn_val;
1617 LLVMValueRef coro_suspend_fn_val;1617 LLVMValueRef coro_suspend_fn_val;
1618 LLVMValueRef coro_end_fn_val;1618 LLVMValueRef coro_end_fn_val;
1619 LLVMValueRef coro_free_fn_val;
1619 bool error_during_imports;1620 bool error_during_imports;
16201621
1621 const char **clang_argv;1622 const char **clang_argv;
src/codegen.cpp+23-1
...@@ -1035,6 +1035,22 @@ static LLVMValueRef get_coro_end_fn_val(CodeGen *g) {...@@ -1035,6 +1035,22 @@ static LLVMValueRef get_coro_end_fn_val(CodeGen *g) {
1035 return g->coro_end_fn_val;1035 return g->coro_end_fn_val;
1036}1036}
10371037
1038static LLVMValueRef get_coro_free_fn_val(CodeGen *g) {
1039 if (g->coro_free_fn_val)
1040 return g->coro_free_fn_val;
1041
1042 LLVMTypeRef param_types[] = {
1043 ZigLLVMTokenTypeInContext(LLVMGetGlobalContext()),
1044 LLVMPointerType(LLVMInt8Type(), 0),
1045 };
1046 LLVMTypeRef fn_type = LLVMFunctionType(LLVMPointerType(LLVMInt8Type(), 0), param_types, 2, false);
1047 Buf *name = buf_sprintf("llvm.coro.free");
1048 g->coro_free_fn_val = LLVMAddFunction(g->module, buf_ptr(name), fn_type);
1049 assert(LLVMGetIntrinsicID(g->coro_free_fn_val));
1050
1051 return g->coro_free_fn_val;
1052}
1053
1038static LLVMValueRef get_return_address_fn_val(CodeGen *g) {1054static LLVMValueRef get_return_address_fn_val(CodeGen *g) {
1039 if (g->return_address_fn_val)1055 if (g->return_address_fn_val)
1040 return g->return_address_fn_val;1056 return g->return_address_fn_val;
...@@ -3909,7 +3925,13 @@ static LLVMValueRef ir_render_coro_end(CodeGen *g, IrExecutable *executable, IrI...@@ -3909,7 +3925,13 @@ static LLVMValueRef ir_render_coro_end(CodeGen *g, IrExecutable *executable, IrI
3909}3925}
39103926
3911static LLVMValueRef ir_render_coro_free(CodeGen *g, IrExecutable *executable, IrInstructionCoroFree *instruction) {3927static LLVMValueRef ir_render_coro_free(CodeGen *g, IrExecutable *executable, IrInstructionCoroFree *instruction) {
3912 zig_panic("TODO ir_render_coro_free");3928 LLVMValueRef coro_id = ir_llvm_value(g, instruction->coro_id);
3929 LLVMValueRef coro_handle = ir_llvm_value(g, instruction->coro_handle);
3930 LLVMValueRef params[] = {
3931 coro_id,
3932 coro_handle,
3933 };
3934 return LLVMBuildCall(g->builder, get_coro_free_fn_val(g), params, 2, "");
3913}3935}
39143936
3915static LLVMValueRef ir_render_coro_resume(CodeGen *g, IrExecutable *executable, IrInstructionCoroResume *instruction) {3937static LLVMValueRef ir_render_coro_resume(CodeGen *g, IrExecutable *executable, IrInstructionCoroResume *instruction) {