aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorkristopher tate <kt@connectfree.co.jp>2018-07-29 12:27:50 +0900
committerkristopher tate <kt@connectfree.co.jp>2018-08-02 16:50:08 +0900
commit92cb330e160388bca7ddd7ceecbd7157ce92247b (patch)
tree0a78b449c82d9981ac0512ea72a2a66f56b67e56 /src
parent13ec5db2348a0f6a4464aa8a513dbf11b72dc3ae (diff)
downloadzig-92cb330e160388bca7ddd7ceecbd7157ce92247b.tar.gz
zig-92cb330e160388bca7ddd7ceecbd7157ce92247b.zip
src/codegen.cpp: @handle(): replace hacky ref chain with llvm intrinsic;
Tracking Issue #1296 ;
Diffstat (limited to 'src')
-rw-r--r--src/all_types.hpp1
-rw-r--r--src/codegen.cpp17
2 files changed, 16 insertions, 2 deletions
diff --git a/src/all_types.hpp b/src/all_types.hpp
index f03a250aea..8d55a75f9f 100644
--- a/src/all_types.hpp
+++ b/src/all_types.hpp
@@ -1717,6 +1717,7 @@ struct CodeGen {
LLVMValueRef coro_save_fn_val;
LLVMValueRef coro_promise_fn_val;
LLVMValueRef coro_alloc_helper_fn_val;
+ LLVMValueRef coro_frame_fn_val;
LLVMValueRef merge_err_ret_traces_fn_val;
LLVMValueRef add_error_return_trace_addr_fn_val;
LLVMValueRef stacksave_fn_val;
diff --git a/src/codegen.cpp b/src/codegen.cpp
index bd708e3824..539356ef2f 100644
--- a/src/codegen.cpp
+++ b/src/codegen.cpp
@@ -4146,11 +4146,24 @@ static LLVMValueRef ir_render_frame_address(CodeGen *g, IrExecutable *executable
return LLVMBuildCall(g->builder, get_frame_address_fn_val(g), &zero, 1, "");
}
+static LLVMValueRef get_handle_fn_val(CodeGen *g) {
+ if (g->coro_frame_fn_val)
+ return g->coro_frame_fn_val;
+
+ LLVMTypeRef fn_type = LLVMFunctionType( LLVMPointerType(LLVMInt8Type(), 0)
+ , nullptr, 0, false);
+ Buf *name = buf_sprintf("llvm.coro.frame");
+ g->coro_frame_fn_val = LLVMAddFunction(g->module, buf_ptr(name), fn_type);
+ assert(LLVMGetIntrinsicID(g->coro_frame_fn_val));
+
+ return g->coro_frame_fn_val;
+}
+
static LLVMValueRef ir_render_handle(CodeGen *g, IrExecutable *executable,
IrInstructionHandle *instruction)
{
- LLVMValueRef ptr = ir_llvm_value(g, executable->fn_entry->ir_executable.coro_handle->other);
- return LLVMBuildBitCast(g->builder, ptr, g->builtin_types.entry_promise->type_ref, "");
+ LLVMValueRef zero = LLVMConstNull(g->builtin_types.entry_promise->type_ref);
+ return LLVMBuildCall(g->builder, get_handle_fn_val(g), &zero, 0, "");
}
static LLVMValueRef render_shl_with_overflow(CodeGen *g, IrInstructionOverflowOp *instruction) {