authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-02-25 15:20:31-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-02-25 15:20:31-05:00
log93cbd4eeb97f30062311d6e083dd056b8fb8b021
treee8644b453c39df5ecb7c8aec88fd20a089930b56
parent9f6c5a20de03a59bfcaead703fe9490a6d622f84

codegen for coro_alloc and coro_size instructions

See #727

2 files changed, 32 insertions(+), 2 deletions(-)

src/all_types.hpp+2
......@@ -1611,6 +1611,8 @@ struct CodeGen {
16111611 LLVMValueRef frame_address_fn_val;
16121612 LLVMValueRef coro_destroy_fn_val;
16131613 LLVMValueRef coro_id_fn_val;
1614 LLVMValueRef coro_alloc_fn_val;
1615 LLVMValueRef coro_size_fn_val;
16141616 bool error_during_imports;
16151617
16161618 const char **clang_argv;
src/codegen.cpp+30-2
......@@ -960,6 +960,33 @@ static LLVMValueRef get_coro_id_fn_val(CodeGen *g) {
960960 return g->coro_id_fn_val;
961961}
962962
963static LLVMValueRef get_coro_alloc_fn_val(CodeGen *g) {
964 if (g->coro_alloc_fn_val)
965 return g->coro_alloc_fn_val;
966
967 LLVMTypeRef param_types[] = {
968 ZigLLVMTokenTypeInContext(LLVMGetGlobalContext()),
969 };
970 LLVMTypeRef fn_type = LLVMFunctionType(LLVMInt1Type(), param_types, 1, false);
971 Buf *name = buf_sprintf("llvm.coro.alloc");
972 g->coro_alloc_fn_val = LLVMAddFunction(g->module, buf_ptr(name), fn_type);
973 assert(LLVMGetIntrinsicID(g->coro_alloc_fn_val));
974
975 return g->coro_alloc_fn_val;
976}
977
978static LLVMValueRef get_coro_size_fn_val(CodeGen *g) {
979 if (g->coro_size_fn_val)
980 return g->coro_size_fn_val;
981
982 LLVMTypeRef fn_type = LLVMFunctionType(g->builtin_types.entry_usize->type_ref, nullptr, 0, false);
983 Buf *name = buf_sprintf("llvm.coro.size.i%d", g->pointer_size_bytes * 8);
984 g->coro_size_fn_val = LLVMAddFunction(g->module, buf_ptr(name), fn_type);
985 assert(LLVMGetIntrinsicID(g->coro_size_fn_val));
986
987 return g->coro_size_fn_val;
988}
989
963990static LLVMValueRef get_return_address_fn_val(CodeGen *g) {
964991 if (g->return_address_fn_val)
965992 return g->return_address_fn_val;
......@@ -3762,11 +3789,12 @@ static LLVMValueRef ir_render_coro_id(CodeGen *g, IrExecutable *executable, IrIn
37623789}
37633790
37643791static LLVMValueRef ir_render_coro_alloc(CodeGen *g, IrExecutable *executable, IrInstructionCoroAlloc *instruction) {
3765 zig_panic("TODO ir_render_coro_alloc");
3792 LLVMValueRef token = ir_llvm_value(g, instruction->coro_id);
3793 return LLVMBuildCall(g->builder, get_coro_alloc_fn_val(g), &token, 1, "");
37663794}
37673795
37683796static LLVMValueRef ir_render_coro_size(CodeGen *g, IrExecutable *executable, IrInstructionCoroSize *instruction) {
3769 zig_panic("TODO ir_render_coro_size");
3797 return LLVMBuildCall(g->builder, get_coro_size_fn_val(g), nullptr, 0, "");
37703798}
37713799
37723800static LLVMValueRef ir_render_coro_begin(CodeGen *g, IrExecutable *executable, IrInstructionCoroBegin *instruction) {