| ... | @@ -960,6 +960,33 @@ static LLVMValueRef get_coro_id_fn_val(CodeGen *g) { | ... | @@ -960,6 +960,33 @@ static LLVMValueRef get_coro_id_fn_val(CodeGen *g) { |
| 960 | return g->coro_id_fn_val; | 960 | return g->coro_id_fn_val; |
| 961 | } | 961 | } |
| 962 | | 962 | |
| | 963 | static 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 | |
| | 978 | static 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 | |
| 963 | static LLVMValueRef get_return_address_fn_val(CodeGen *g) { | 990 | static LLVMValueRef get_return_address_fn_val(CodeGen *g) { |
| 964 | if (g->return_address_fn_val) | 991 | if (g->return_address_fn_val) |
| 965 | return g->return_address_fn_val; | 992 | return g->return_address_fn_val; |
| ... | @@ -3762,11 +3789,12 @@ static LLVMValueRef ir_render_coro_id(CodeGen *g, IrExecutable *executable, IrIn | ... | @@ -3762,11 +3789,12 @@ static LLVMValueRef ir_render_coro_id(CodeGen *g, IrExecutable *executable, IrIn |
| 3762 | } | 3789 | } |
| 3763 | | 3790 | |
| 3764 | static LLVMValueRef ir_render_coro_alloc(CodeGen *g, IrExecutable *executable, IrInstructionCoroAlloc *instruction) { | 3791 | static 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, ""); |
| 3766 | } | 3794 | } |
| 3767 | | 3795 | |
| 3768 | static LLVMValueRef ir_render_coro_size(CodeGen *g, IrExecutable *executable, IrInstructionCoroSize *instruction) { | 3796 | static 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, ""); |
| 3770 | } | 3798 | } |
| 3771 | | 3799 | |
| 3772 | static LLVMValueRef ir_render_coro_begin(CodeGen *g, IrExecutable *executable, IrInstructionCoroBegin *instruction) { | 3800 | static LLVMValueRef ir_render_coro_begin(CodeGen *g, IrExecutable *executable, IrInstructionCoroBegin *instruction) { |