authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-02-26 11:52:29-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-02-26 21:31:00-05:00
log4e43bde924694a640cfec13141df1f3f611ffe0f
treeb0ce3a75a10248bcbc0350afd83928f7a88baea1
parent4ac6c4d6bfb8f7ada2799ddb5ce3a9797be0518d

workaround for llvm: delete coroutine allocation elision

maybe this can be reverted, but it seems to be related to llvm's coro transformations crashing. See #727

1 files changed, 3 insertions(+), 39 deletions(-)

src/ir.cpp+3-39
...@@ -6095,7 +6095,6 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec...@@ -6095,7 +6095,6 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec
6095 IrInstruction *coro_id;6095 IrInstruction *coro_id;
6096 IrInstruction *coro_promise_ptr;6096 IrInstruction *coro_promise_ptr;
6097 IrInstruction *coro_result_field_ptr;6097 IrInstruction *coro_result_field_ptr;
6098 IrInstruction *coro_need_dyn_alloc;
6099 TypeTableEntry *return_type;6098 TypeTableEntry *return_type;
6100 Buf *result_ptr_field_name;6099 Buf *result_ptr_field_name;
6101 if (is_async) {6100 if (is_async) {
...@@ -6113,15 +6112,6 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec...@@ -6113,15 +6112,6 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec
6113 get_pointer_to_type(irb->codegen, irb->codegen->builtin_types.entry_u8, false));6112 get_pointer_to_type(irb->codegen, irb->codegen->builtin_types.entry_u8, false));
6114 IrInstruction *promise_as_u8_ptr = ir_build_ptr_cast(irb, scope, node, u8_ptr_type, coro_promise_ptr);6113 IrInstruction *promise_as_u8_ptr = ir_build_ptr_cast(irb, scope, node, u8_ptr_type, coro_promise_ptr);
6115 coro_id = ir_build_coro_id(irb, scope, node, promise_as_u8_ptr);6114 coro_id = ir_build_coro_id(irb, scope, node, promise_as_u8_ptr);
6116 coro_need_dyn_alloc = ir_build_coro_alloc(irb, scope, node, coro_id);
6117 IrInstruction *zero = ir_build_const_usize(irb, scope, node, 0);
6118 IrInstruction *null_ptr = ir_build_int_to_ptr(irb, scope, node, u8_ptr_type, zero);
6119
6120 IrBasicBlock *dyn_alloc_block = ir_create_basic_block(irb, scope, "DynAlloc");
6121 IrBasicBlock *coro_begin_block = ir_create_basic_block(irb, scope, "CoroBegin");
6122 ir_build_cond_br(irb, scope, node, coro_need_dyn_alloc, dyn_alloc_block, coro_begin_block, const_bool_false);
6123
6124 ir_set_cursor_at_end_and_append_block(irb, dyn_alloc_block);
6125 IrInstruction *coro_size = ir_build_coro_size(irb, scope, node);6115 IrInstruction *coro_size = ir_build_coro_size(irb, scope, node);
6126 irb->exec->implicit_allocator_ptr = ir_build_get_implicit_allocator(irb, scope, node, ImplicitAllocatorIdContext);6116 irb->exec->implicit_allocator_ptr = ir_build_get_implicit_allocator(irb, scope, node, ImplicitAllocatorIdContext);
6127 IrInstruction *alloc_fn = ir_build_get_implicit_allocator(irb, scope, node, ImplicitAllocatorIdAlloc);6117 IrInstruction *alloc_fn = ir_build_get_implicit_allocator(irb, scope, node, ImplicitAllocatorIdAlloc);
...@@ -6144,31 +6134,11 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec...@@ -6144,31 +6134,11 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec
6144 ir_build_coro_alloc_fail(irb, scope, node, err_val);6134 ir_build_coro_alloc_fail(irb, scope, node, err_val);
61456135
6146 ir_set_cursor_at_end_and_append_block(irb, alloc_ok_block);6136 ir_set_cursor_at_end_and_append_block(irb, alloc_ok_block);
6147 IrInstruction *unwrapped_mem_ptr = ir_build_unwrap_err_payload(irb, scope, node, alloc_result_ptr, false);6137 coro_unwrapped_mem_ptr = ir_build_unwrap_err_payload(irb, scope, node, alloc_result_ptr, false);
6148 Buf *ptr_field_name = buf_create_from_str("ptr");6138 Buf *ptr_field_name = buf_create_from_str("ptr");
6149 IrInstruction *coro_mem_ptr_field = ir_build_field_ptr(irb, scope, node, unwrapped_mem_ptr,6139 IrInstruction *coro_mem_ptr_field = ir_build_field_ptr(irb, scope, node, coro_unwrapped_mem_ptr,
6150 ptr_field_name);6140 ptr_field_name);
6151 IrInstruction *coro_mem_ptr = ir_build_load_ptr(irb, scope, node, coro_mem_ptr_field);6141 IrInstruction *coro_mem = ir_build_load_ptr(irb, scope, node, coro_mem_ptr_field);
6152 ir_build_br(irb, scope, node, coro_begin_block, const_bool_false);
6153
6154 ir_set_cursor_at_end_and_append_block(irb, coro_begin_block);
6155
6156 IrBasicBlock **coro_mem_incoming_blocks = allocate<IrBasicBlock *>(2);
6157 IrInstruction **coro_mem_incoming_values = allocate<IrInstruction *>(2);
6158 coro_mem_incoming_blocks[0] = entry_block;
6159 coro_mem_incoming_values[0] = null_ptr;
6160 coro_mem_incoming_blocks[1] = alloc_ok_block;
6161 coro_mem_incoming_values[1] = coro_mem_ptr;
6162 IrInstruction *coro_mem = ir_build_phi(irb, scope, node, 2, coro_mem_incoming_blocks, coro_mem_incoming_values);
6163
6164 IrBasicBlock **unwrapped_mem_ptr_incoming_blocks = allocate<IrBasicBlock *>(2);
6165 IrInstruction **unwrapped_mem_ptr_incoming_values = allocate<IrInstruction *>(2);
6166 unwrapped_mem_ptr_incoming_blocks[0] = entry_block;
6167 unwrapped_mem_ptr_incoming_values[0] = ir_build_const_undefined(irb, scope, node);
6168 unwrapped_mem_ptr_incoming_blocks[1] = alloc_ok_block;
6169 unwrapped_mem_ptr_incoming_values[1] = unwrapped_mem_ptr;
6170 coro_unwrapped_mem_ptr = ir_build_phi(irb, scope, node, 2,
6171 unwrapped_mem_ptr_incoming_blocks, unwrapped_mem_ptr_incoming_values);
61726142
6173 irb->exec->coro_handle = ir_build_coro_begin(irb, scope, node, coro_id, coro_mem);6143 irb->exec->coro_handle = ir_build_coro_begin(irb, scope, node, coro_id, coro_mem);
61746144
...@@ -6245,20 +6215,14 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec...@@ -6245,20 +6215,14 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec
6245 incoming_blocks[1] = irb->exec->coro_normal_final;6215 incoming_blocks[1] = irb->exec->coro_normal_final;
6246 incoming_values[1] = const_bool_true;6216 incoming_values[1] = const_bool_true;
6247 IrInstruction *resume_awaiter = ir_build_phi(irb, scope, node, 2, incoming_blocks, incoming_values);6217 IrInstruction *resume_awaiter = ir_build_phi(irb, scope, node, 2, incoming_blocks, incoming_values);
6248 IrBasicBlock *dyn_free_block = ir_create_basic_block(irb, scope, "DynFree");
6249 IrBasicBlock *end_free_block = ir_create_basic_block(irb, scope, "EndFree");
6250 ir_build_cond_br(irb, scope, node, coro_need_dyn_alloc, dyn_free_block, end_free_block, const_bool_false);
62516218
6252 ir_set_cursor_at_end_and_append_block(irb, dyn_free_block);
6253 IrInstruction *free_fn = ir_build_get_implicit_allocator(irb, scope, node, ImplicitAllocatorIdFree);6219 IrInstruction *free_fn = ir_build_get_implicit_allocator(irb, scope, node, ImplicitAllocatorIdFree);
6254 size_t arg_count = 2;6220 size_t arg_count = 2;
6255 IrInstruction **args = allocate<IrInstruction *>(arg_count);6221 IrInstruction **args = allocate<IrInstruction *>(arg_count);
6256 args[0] = irb->exec->implicit_allocator_ptr; // self6222 args[0] = irb->exec->implicit_allocator_ptr; // self
6257 args[1] = ir_build_load_ptr(irb, scope, node, coro_unwrapped_mem_ptr); // old_mem6223 args[1] = ir_build_load_ptr(irb, scope, node, coro_unwrapped_mem_ptr); // old_mem
6258 ir_build_call(irb, scope, node, nullptr, free_fn, arg_count, args, false, FnInlineAuto, false, nullptr, nullptr, nullptr);6224 ir_build_call(irb, scope, node, nullptr, free_fn, arg_count, args, false, FnInlineAuto, false, nullptr, nullptr, nullptr);
6259 ir_build_br(irb, scope, node, end_free_block, const_bool_false);
62606225
6261 ir_set_cursor_at_end_and_append_block(irb, end_free_block);
6262 IrBasicBlock *resume_block = ir_create_basic_block(irb, scope, "Resume");6226 IrBasicBlock *resume_block = ir_create_basic_block(irb, scope, "Resume");
6263 IrBasicBlock *return_block = ir_create_basic_block(irb, scope, "Return");6227 IrBasicBlock *return_block = ir_create_basic_block(irb, scope, "Return");
6264 ir_build_cond_br(irb, scope, node, resume_awaiter, resume_block, return_block, const_bool_false);6228 ir_build_cond_br(irb, scope, node, resume_awaiter, resume_block, return_block, const_bool_false);