authorgravatar for kt@connectfree.co.jpkristopher tate <kt@connectfree.co.jp> 2018-07-29 12:27:50+09:00
committergravatar for kt@connectfree.co.jpkristopher tate <kt@connectfree.co.jp> 2018-08-02 16:50:08+09:00
log92cb330e160388bca7ddd7ceecbd7157ce92247b
tree0a78b449c82d9981ac0512ea72a2a66f56b67e56
parent13ec5db2348a0f6a4464aa8a513dbf11b72dc3ae

src/codegen.cpp: @handle(): replace hacky ref chain with llvm intrinsic;

Tracking Issue #1296 ;

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

src/all_types.hpp+1
...@@ -1717,6 +1717,7 @@ struct CodeGen {...@@ -1717,6 +1717,7 @@ struct CodeGen {
1717 LLVMValueRef coro_save_fn_val;1717 LLVMValueRef coro_save_fn_val;
1718 LLVMValueRef coro_promise_fn_val;1718 LLVMValueRef coro_promise_fn_val;
1719 LLVMValueRef coro_alloc_helper_fn_val;1719 LLVMValueRef coro_alloc_helper_fn_val;
1720 LLVMValueRef coro_frame_fn_val;
1720 LLVMValueRef merge_err_ret_traces_fn_val;1721 LLVMValueRef merge_err_ret_traces_fn_val;
1721 LLVMValueRef add_error_return_trace_addr_fn_val;1722 LLVMValueRef add_error_return_trace_addr_fn_val;
1722 LLVMValueRef stacksave_fn_val;1723 LLVMValueRef stacksave_fn_val;
src/codegen.cpp+15-2
...@@ -4146,11 +4146,24 @@ static LLVMValueRef ir_render_frame_address(CodeGen *g, IrExecutable *executable...@@ -4146,11 +4146,24 @@ static LLVMValueRef ir_render_frame_address(CodeGen *g, IrExecutable *executable
4146 return LLVMBuildCall(g->builder, get_frame_address_fn_val(g), &zero, 1, "");4146 return LLVMBuildCall(g->builder, get_frame_address_fn_val(g), &zero, 1, "");
4147}4147}
41484148
4149static LLVMValueRef get_handle_fn_val(CodeGen *g) {
4150 if (g->coro_frame_fn_val)
4151 return g->coro_frame_fn_val;
4152
4153 LLVMTypeRef fn_type = LLVMFunctionType( LLVMPointerType(LLVMInt8Type(), 0)
4154 , nullptr, 0, false);
4155 Buf *name = buf_sprintf("llvm.coro.frame");
4156 g->coro_frame_fn_val = LLVMAddFunction(g->module, buf_ptr(name), fn_type);
4157 assert(LLVMGetIntrinsicID(g->coro_frame_fn_val));
4158
4159 return g->coro_frame_fn_val;
4160}
4161
4149static LLVMValueRef ir_render_handle(CodeGen *g, IrExecutable *executable,4162static LLVMValueRef ir_render_handle(CodeGen *g, IrExecutable *executable,
4150 IrInstructionHandle *instruction)4163 IrInstructionHandle *instruction)
4151{4164{
4152 LLVMValueRef ptr = ir_llvm_value(g, executable->fn_entry->ir_executable.coro_handle->other);4165 LLVMValueRef zero = LLVMConstNull(g->builtin_types.entry_promise->type_ref);
4153 return LLVMBuildBitCast(g->builder, ptr, g->builtin_types.entry_promise->type_ref, "");4166 return LLVMBuildCall(g->builder, get_handle_fn_val(g), &zero, 0, "");
4154}4167}
41554168
4156static LLVMValueRef render_shl_with_overflow(CodeGen *g, IrInstructionOverflowOp *instruction) {4169static LLVMValueRef render_shl_with_overflow(CodeGen *g, IrInstructionOverflowOp *instruction) {