authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-02-27 17:47:18-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-02-27 17:47:18-05:00
logd24345386274e3abcbcc676fe65bda127c06ce8e
treeb5945c207d3ce6dff2631af9c30f35d2e72c6c55
parent138d6f909321fb4fddeaa172357336c384c64eda

Revert "llvm coroutine workaround: sret functions return sret pointer"

This reverts commit 132e604aa399a3bcb91996e550cf8972bd88422c. this workaround didn't work either

2 files changed, 4 insertions(+), 14 deletions(-)

src/analyze.cpp+1-4
...@@ -1026,10 +1026,7 @@ TypeTableEntry *get_fn_type(CodeGen *g, FnTypeId *fn_type_id) {...@@ -1026,10 +1026,7 @@ TypeTableEntry *get_fn_type(CodeGen *g, FnTypeId *fn_type_id) {
1026 gen_param_index += 1;1026 gen_param_index += 1;
1027 // after the gen_param_index += 1 because 0 is the return type1027 // after the gen_param_index += 1 because 0 is the return type
1028 param_di_types[gen_param_index] = gen_type->di_type;1028 param_di_types[gen_param_index] = gen_type->di_type;
10291029 gen_return_type = g->builtin_types.entry_void;
1030 // as a workaround for LLVM coroutines not understanding instruction dependencies,
1031 // we return the sret pointer argument instead of returning void
1032 gen_return_type = gen_type;
1033 } else {1030 } else {
1034 gen_return_type = fn_type_id->return_type;1031 gen_return_type = fn_type_id->return_type;
1035 }1032 }
src/codegen.cpp+3-10
...@@ -547,10 +547,7 @@ static LLVMValueRef fn_llvm_value(CodeGen *g, FnTableEntry *fn_table_entry) {...@@ -547,10 +547,7 @@ static LLVMValueRef fn_llvm_value(CodeGen *g, FnTableEntry *fn_table_entry) {
547 } else if (handle_is_ptr(return_type) &&547 } else if (handle_is_ptr(return_type) &&
548 calling_convention_does_first_arg_return(fn_type->data.fn.fn_type_id.cc))548 calling_convention_does_first_arg_return(fn_type->data.fn.fn_type_id.cc))
549 {549 {
550 // We do not add the sret attribute, because it would require the return type to be void,550 addLLVMArgAttr(fn_table_entry->llvm_value, 0, "sret");
551 // and we want the return value to return the sret pointer, to work around LLVM Coroutine
552 // transformation passes not understanding the data dependency.
553 //addLLVMArgAttr(fn_table_entry->llvm_value, 0, "sret");
554 addLLVMArgAttr(fn_table_entry->llvm_value, 0, "nonnull");551 addLLVMArgAttr(fn_table_entry->llvm_value, 0, "nonnull");
555 }552 }
556553
...@@ -1619,9 +1616,7 @@ static LLVMValueRef ir_render_return(CodeGen *g, IrExecutable *executable, IrIns...@@ -1619,9 +1616,7 @@ static LLVMValueRef ir_render_return(CodeGen *g, IrExecutable *executable, IrIns
1619 if (calling_convention_does_first_arg_return(g->cur_fn->type_entry->data.fn.fn_type_id.cc)) {1616 if (calling_convention_does_first_arg_return(g->cur_fn->type_entry->data.fn.fn_type_id.cc)) {
1620 assert(g->cur_ret_ptr);1617 assert(g->cur_ret_ptr);
1621 gen_assign_raw(g, g->cur_ret_ptr, get_pointer_to_type(g, return_type, false), value);1618 gen_assign_raw(g, g->cur_ret_ptr, get_pointer_to_type(g, return_type, false), value);
1622 // as a workaround for LLVM coroutines not understanding instruction dependencies,1619 LLVMBuildRetVoid(g->builder);
1623 // we return the sret pointer argument instead of returning void
1624 LLVMBuildRet(g->builder, g->cur_ret_ptr);
1625 } else {1620 } else {
1626 LLVMValueRef by_val_value = gen_load_untyped(g, value, 0, false, "");1621 LLVMValueRef by_val_value = gen_load_untyped(g, value, 0, false, "");
1627 LLVMBuildRet(g->builder, by_val_value);1622 LLVMBuildRet(g->builder, by_val_value);
...@@ -2774,9 +2769,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr...@@ -2774,9 +2769,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr
2774 } else if (!ret_has_bits) {2769 } else if (!ret_has_bits) {
2775 return nullptr;2770 return nullptr;
2776 } else if (first_arg_ret) {2771 } else if (first_arg_ret) {
2777 // instead of returning instruction->tmp_ptr here, we trust that the function returned the first arg.2772 return instruction->tmp_ptr;
2778 // this is a workaround for llvm coroutines not understanding the data dependency
2779 return result;
2780 } else {2773 } else {
2781 return result;2774 return result;
2782 }2775 }