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 {
16161616 LLVMValueRef coro_begin_fn_val;
16171617 LLVMValueRef coro_suspend_fn_val;
16181618 LLVMValueRef coro_end_fn_val;
1619 LLVMValueRef coro_free_fn_val;
16191620 bool error_during_imports;
16201621
16211622 const char **clang_argv;
src/codegen.cpp+23-1
......@@ -1035,6 +1035,22 @@ static LLVMValueRef get_coro_end_fn_val(CodeGen *g) {
10351035 return g->coro_end_fn_val;
10361036}
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
10381054static LLVMValueRef get_return_address_fn_val(CodeGen *g) {
10391055 if (g->return_address_fn_val)
10401056 return g->return_address_fn_val;
......@@ -3909,7 +3925,13 @@ static LLVMValueRef ir_render_coro_end(CodeGen *g, IrExecutable *executable, IrI
39093925}
39103926
39113927static 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, "");
39133935}
39143936
39153937static LLVMValueRef ir_render_coro_resume(CodeGen *g, IrExecutable *executable, IrInstructionCoroResume *instruction) {