authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-02-28 22:01:13-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-02-28 22:01:13-07:00
log72404db31f76635f11d0aa4dcc02c149ef885b3d
tree503a7b8732a3fa0b4fa408fd7dd63a579b16eb92
parent6af6c3c9791b655b3adca08749baf89404b081ae

stage1: update to LLVM 12 sret callsite requirements

Without this, the LLVM IR that zig generates cannot be compiled by LLVM.

3 files changed, 11 insertions(+), 7 deletions(-)

src/stage1/codegen.cpp+1-7
......@@ -4037,12 +4037,6 @@ static void gen_set_stack_pointer(CodeGen *g, LLVMValueRef aligned_end_addr) {
40374037 LLVMBuildCall(g->builder, write_register_fn_val, params, 2, "");
40384038}
40394039
4040static void set_call_instr_sret(CodeGen *g, LLVMValueRef call_instr) {
4041 unsigned attr_kind_id = LLVMGetEnumAttributeKindForName("sret", 4);
4042 LLVMAttributeRef sret_attr = LLVMCreateEnumAttribute(LLVMGetGlobalContext(), attr_kind_id, 0);
4043 LLVMAddCallSiteAttribute(call_instr, 1, sret_attr);
4044}
4045
40464040static void render_async_spills(CodeGen *g) {
40474041 ZigType *fn_type = g->cur_fn->type_entry;
40484042 ZigType *import = get_scope_import(&g->cur_fn->fndef_scope->base);
......@@ -4558,7 +4552,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutableGen *executable, IrIn
45584552 } else if (!ret_has_bits) {
45594553 return nullptr;
45604554 } else if (first_arg_ret) {
4561 set_call_instr_sret(g, result);
4555 ZigLLVMSetCallSret(result, get_llvm_type(g, src_return_type));
45624556 return result_loc;
45634557 } else if (handle_is_ptr(g, src_return_type)) {
45644558 LLVMValueRef store_instr = LLVMBuildStore(g->builder, result, result_loc);
src/zig_llvm.cpp+9
......@@ -940,6 +940,15 @@ void ZigLLVMSetTailCall(LLVMValueRef Call) {
940940 unwrap<CallInst>(Call)->setTailCallKind(CallInst::TCK_MustTail);
941941}
942942
943void ZigLLVMSetCallSret(LLVMValueRef Call, LLVMTypeRef return_type) {
944 const AttributeList attr_set = unwrap<CallInst>(Call)->getAttributes();
945 AttrBuilder attr_builder;
946 Type *llvm_type = unwrap<Type>(return_type);
947 attr_builder.addStructRetAttr(llvm_type);
948 const AttributeList new_attr_set = attr_set.addAttributes(unwrap<CallInst>(Call)->getContext(), 1, attr_builder);
949 unwrap<CallInst>(Call)->setAttributes(new_attr_set);
950}
951
943952void ZigLLVMFunctionSetPrefixData(LLVMValueRef function, LLVMValueRef data) {
944953 unwrap<Function>(function)->setPrefixData(unwrap<Constant>(data));
945954}
src/zig_llvm.h+1
......@@ -264,6 +264,7 @@ ZIG_EXTERN_C struct ZigLLVMDILocation *ZigLLVMGetDebugLoc(unsigned line, unsigne
264264
265265ZIG_EXTERN_C void ZigLLVMSetFastMath(LLVMBuilderRef builder_wrapped, bool on_state);
266266ZIG_EXTERN_C void ZigLLVMSetTailCall(LLVMValueRef Call);
267ZIG_EXTERN_C void ZigLLVMSetCallSret(LLVMValueRef Call, LLVMTypeRef return_type);
267268ZIG_EXTERN_C void ZigLLVMFunctionSetPrefixData(LLVMValueRef fn, LLVMValueRef data);
268269ZIG_EXTERN_C void ZigLLVMFunctionSetCallingConv(LLVMValueRef function, enum ZigLLVM_CallingConv cc);
269270