| ... | @@ -1092,7 +1092,7 @@ static void gen_panic(CodeGen *g, LLVMValueRef msg_arg, LLVMValueRef stack_trace | ... | @@ -1092,7 +1092,7 @@ static void gen_panic(CodeGen *g, LLVMValueRef msg_arg, LLVMValueRef stack_trace |
| 1092 | msg_arg, | 1092 | msg_arg, |
| 1093 | stack_trace_arg, | 1093 | stack_trace_arg, |
| 1094 | }; | 1094 | }; |
| 1095 | ZigLLVMBuildCall(g->builder, LLVMTypeOf(fn_val), fn_val, args, 2, llvm_cc, ZigLLVM_CallAttrAuto, ""); | 1095 | ZigLLVMBuildCall(g->builder, LLVMGlobalGetValueType(fn_val), fn_val, args, 2, llvm_cc, ZigLLVM_CallAttrAuto, ""); |
| 1096 | if (!stack_trace_is_llvm_alloca) { | 1096 | if (!stack_trace_is_llvm_alloca) { |
| 1097 | // The stack trace argument is not in the stack of the caller, so | 1097 | // The stack trace argument is not in the stack of the caller, so |
| 1098 | // we'd like to set tail call here, but because slices (the type of msg_arg) are | 1098 | // we'd like to set tail call here, but because slices (the type of msg_arg) are |
| ... | @@ -1369,7 +1369,7 @@ static LLVMValueRef get_return_err_fn(CodeGen *g) { | ... | @@ -1369,7 +1369,7 @@ static LLVMValueRef get_return_err_fn(CodeGen *g) { |
| 1369 | | 1369 | |
| 1370 | LLVMPositionBuilderAtEnd(g->builder, dest_non_null_block); | 1370 | LLVMPositionBuilderAtEnd(g->builder, dest_non_null_block); |
| 1371 | LLVMValueRef args[] = { err_ret_trace_ptr, return_address }; | 1371 | LLVMValueRef args[] = { err_ret_trace_ptr, return_address }; |
| 1372 | ZigLLVMBuildCall(g->builder, LLVMTypeOf(add_error_return_trace_addr_fn_val), | 1372 | ZigLLVMBuildCall(g->builder, LLVMGlobalGetValueType(add_error_return_trace_addr_fn_val), |
| 1373 | add_error_return_trace_addr_fn_val, args, 2, | 1373 | add_error_return_trace_addr_fn_val, args, 2, |
| 1374 | get_llvm_cc(g, CallingConventionUnspecified), ZigLLVM_CallAttrAlwaysInline, ""); | 1374 | get_llvm_cc(g, CallingConventionUnspecified), ZigLLVM_CallAttrAlwaysInline, ""); |
| 1375 | LLVMBuildRetVoid(g->builder); | 1375 | LLVMBuildRetVoid(g->builder); |
| ... | @@ -1546,14 +1546,14 @@ static void gen_safety_crash_for_err(CodeGen *g, LLVMValueRef err_val, Scope *sc | ... | @@ -1546,14 +1546,14 @@ static void gen_safety_crash_for_err(CodeGen *g, LLVMValueRef err_val, Scope *sc |
| 1546 | err_ret_trace_val, | 1546 | err_ret_trace_val, |
| 1547 | err_val, | 1547 | err_val, |
| 1548 | }; | 1548 | }; |
| 1549 | call_instruction = ZigLLVMBuildCall(g->builder, LLVMTypeOf(safety_crash_err_fn), | 1549 | call_instruction = ZigLLVMBuildCall(g->builder, LLVMGlobalGetValueType(safety_crash_err_fn), |
| 1550 | safety_crash_err_fn, args, 2, | 1550 | safety_crash_err_fn, args, 2, |
| 1551 | get_llvm_cc(g, CallingConventionUnspecified), ZigLLVM_CallAttrAuto, ""); | 1551 | get_llvm_cc(g, CallingConventionUnspecified), ZigLLVM_CallAttrAuto, ""); |
| 1552 | } else { | 1552 | } else { |
| 1553 | LLVMValueRef args[] = { | 1553 | LLVMValueRef args[] = { |
| 1554 | err_val, | 1554 | err_val, |
| 1555 | }; | 1555 | }; |
| 1556 | call_instruction = ZigLLVMBuildCall(g->builder, LLVMTypeOf(safety_crash_err_fn), | 1556 | call_instruction = ZigLLVMBuildCall(g->builder, LLVMGlobalGetValueType(safety_crash_err_fn), |
| 1557 | safety_crash_err_fn, args, 1, | 1557 | safety_crash_err_fn, args, 1, |
| 1558 | get_llvm_cc(g, CallingConventionUnspecified), ZigLLVM_CallAttrAuto, ""); | 1558 | get_llvm_cc(g, CallingConventionUnspecified), ZigLLVM_CallAttrAuto, ""); |
| 1559 | } | 1559 | } |
| ... | @@ -1732,7 +1732,7 @@ static LLVMValueRef gen_soft_float_widen_or_shorten(CodeGen *g, ZigType *actual_ | ... | @@ -1732,7 +1732,7 @@ static LLVMValueRef gen_soft_float_widen_or_shorten(CodeGen *g, ZigType *actual_ |
| 1732 | func_ref = LLVMAddFunction(g->module, fn_name, fn_type); | 1732 | func_ref = LLVMAddFunction(g->module, fn_name, fn_type); |
| 1733 | } | 1733 | } |
| 1734 | | 1734 | |
| 1735 | result = LLVMBuildCall2(g->builder, LLVMTypeOf(func_ref), func_ref, &expr_val, 1, ""); | 1735 | result = LLVMBuildCall2(g->builder, LLVMGlobalGetValueType(func_ref), func_ref, &expr_val, 1, ""); |
| 1736 | | 1736 | |
| 1737 | // On non-Arm platforms we need to bitcast __trunc<>fhf2 result back to f16 | 1737 | // On non-Arm platforms we need to bitcast __trunc<>fhf2 result back to f16 |
| 1738 | if (castTruncatedToF16) { | 1738 | if (castTruncatedToF16) { |
| ... | @@ -1878,7 +1878,7 @@ static LLVMValueRef gen_overflow_op(CodeGen *g, ZigType *operand_type, AddSubMul | ... | @@ -1878,7 +1878,7 @@ static LLVMValueRef gen_overflow_op(CodeGen *g, ZigType *operand_type, AddSubMul |
| 1878 | val1, | 1878 | val1, |
| 1879 | val2, | 1879 | val2, |
| 1880 | }; | 1880 | }; |
| 1881 | LLVMValueRef result_struct = LLVMBuildCall2(g->builder, LLVMTypeOf(fn_val), fn_val, params, 2, ""); | 1881 | LLVMValueRef result_struct = LLVMBuildCall2(g->builder, LLVMGlobalGetValueType(fn_val), fn_val, params, 2, ""); |
| 1882 | LLVMValueRef result = LLVMBuildExtractValue(g->builder, result_struct, 0, ""); | 1882 | LLVMValueRef result = LLVMBuildExtractValue(g->builder, result_struct, 0, ""); |
| 1883 | LLVMValueRef overflow_bit = LLVMBuildExtractValue(g->builder, result_struct, 1, ""); | 1883 | LLVMValueRef overflow_bit = LLVMBuildExtractValue(g->builder, result_struct, 1, ""); |
| 1884 | if (operand_type->id == ZigTypeIdVector) { | 1884 | if (operand_type->id == ZigTypeIdVector) { |
| ... | @@ -2663,7 +2663,7 @@ static LLVMValueRef get_merge_err_ret_traces_fn_val(CodeGen *g) { | ... | @@ -2663,7 +2663,7 @@ static LLVMValueRef get_merge_err_ret_traces_fn_val(CodeGen *g) { |
| 2663 | LLVMValueRef this_addr_val = LLVMBuildLoad2(g->builder, LLVMGetGEPSourceElementType(addr_ptr), | 2663 | LLVMValueRef this_addr_val = LLVMBuildLoad2(g->builder, LLVMGetGEPSourceElementType(addr_ptr), |
| 2664 | addr_ptr, ""); | 2664 | addr_ptr, ""); |
| 2665 | LLVMValueRef args[] = {dest_stack_trace_ptr, this_addr_val}; | 2665 | LLVMValueRef args[] = {dest_stack_trace_ptr, this_addr_val}; |
| 2666 | ZigLLVMBuildCall(g->builder, LLVMTypeOf(add_error_return_trace_addr_fn_val), | 2666 | ZigLLVMBuildCall(g->builder, LLVMGlobalGetValueType(add_error_return_trace_addr_fn_val), |
| 2667 | add_error_return_trace_addr_fn_val, args, 2, get_llvm_cc(g, CallingConventionUnspecified), ZigLLVM_CallAttrAlwaysInline, ""); | 2667 | add_error_return_trace_addr_fn_val, args, 2, get_llvm_cc(g, CallingConventionUnspecified), ZigLLVM_CallAttrAlwaysInline, ""); |
| 2668 | LLVMValueRef prev_frames_left = LLVMBuildLoad2(g->builder, usize_type_ref, frames_left_ptr, ""); | 2668 | LLVMValueRef prev_frames_left = LLVMBuildLoad2(g->builder, usize_type_ref, frames_left_ptr, ""); |
| 2669 | LLVMValueRef new_frames_left = LLVMBuildNUWSub(g->builder, prev_frames_left, usize_one, ""); | 2669 | LLVMValueRef new_frames_left = LLVMBuildNUWSub(g->builder, prev_frames_left, usize_one, ""); |
| ... | @@ -2703,7 +2703,7 @@ static LLVMValueRef ir_render_save_err_ret_addr(CodeGen *g, Stage1Air *executabl | ... | @@ -2703,7 +2703,7 @@ static LLVMValueRef ir_render_save_err_ret_addr(CodeGen *g, Stage1Air *executabl |
| 2703 | bool is_llvm_alloca; | 2703 | bool is_llvm_alloca; |
| 2704 | LLVMValueRef my_err_trace_val = get_cur_err_ret_trace_val(g, save_err_ret_addr_instruction->base.scope, | 2704 | LLVMValueRef my_err_trace_val = get_cur_err_ret_trace_val(g, save_err_ret_addr_instruction->base.scope, |
| 2705 | &is_llvm_alloca); | 2705 | &is_llvm_alloca); |
| 2706 | ZigLLVMBuildCall(g->builder, LLVMTypeOf(return_err_fn), return_err_fn, &my_err_trace_val, 1, | 2706 | ZigLLVMBuildCall(g->builder, LLVMGlobalGetValueType(return_err_fn), return_err_fn, &my_err_trace_val, 1, |
| 2707 | get_llvm_cc(g, CallingConventionUnspecified), ZigLLVM_CallAttrAuto, ""); | 2707 | get_llvm_cc(g, CallingConventionUnspecified), ZigLLVM_CallAttrAuto, ""); |
| 2708 | | 2708 | |
| 2709 | ZigType *ret_type = g->cur_fn->type_entry->data.fn.fn_type_id.return_type; | 2709 | ZigType *ret_type = g->cur_fn->type_entry->data.fn.fn_type_id.return_type; |
| ... | @@ -2753,7 +2753,7 @@ static LLVMValueRef gen_resume(CodeGen *g, LLVMValueRef fn_val, LLVMValueRef tar | ... | @@ -2753,7 +2753,7 @@ static LLVMValueRef gen_resume(CodeGen *g, LLVMValueRef fn_val, LLVMValueRef tar |
| 2753 | LLVMValueRef arg_val = LLVMConstSub(LLVMConstAllOnes(usize_type_ref), | 2753 | LLVMValueRef arg_val = LLVMConstSub(LLVMConstAllOnes(usize_type_ref), |
| 2754 | LLVMConstInt(usize_type_ref, resume_id, false)); | 2754 | LLVMConstInt(usize_type_ref, resume_id, false)); |
| 2755 | LLVMValueRef args[] = {target_frame_ptr, arg_val}; | 2755 | LLVMValueRef args[] = {target_frame_ptr, arg_val}; |
| 2756 | return ZigLLVMBuildCall(g->builder, LLVMTypeOf(fn_val), fn_val, args, 2, ZigLLVM_Fast, ZigLLVM_CallAttrAuto, ""); | 2756 | return ZigLLVMBuildCall(g->builder, LLVMGlobalGetValueType(fn_val), fn_val, args, 2, ZigLLVM_Fast, ZigLLVM_CallAttrAuto, ""); |
| 2757 | } | 2757 | } |
| 2758 | | 2758 | |
| 2759 | static LLVMBasicBlockRef gen_suspend_begin(CodeGen *g, const char *name_hint) { | 2759 | static LLVMBasicBlockRef gen_suspend_begin(CodeGen *g, const char *name_hint) { |
| ... | @@ -2885,7 +2885,7 @@ static void gen_async_return(CodeGen *g, Stage1AirInstReturn *instruction) { | ... | @@ -2885,7 +2885,7 @@ static void gen_async_return(CodeGen *g, Stage1AirInstReturn *instruction) { |
| 2885 | bool is_llvm_alloca; | 2885 | bool is_llvm_alloca; |
| 2886 | LLVMValueRef my_err_trace_val = get_cur_err_ret_trace_val(g, instruction->base.scope, &is_llvm_alloca); | 2886 | LLVMValueRef my_err_trace_val = get_cur_err_ret_trace_val(g, instruction->base.scope, &is_llvm_alloca); |
| 2887 | LLVMValueRef args[] = { dest_trace_ptr, my_err_trace_val }; | 2887 | LLVMValueRef args[] = { dest_trace_ptr, my_err_trace_val }; |
| 2888 | ZigLLVMBuildCall(g->builder, LLVMTypeOf(get_merge_err_ret_traces_fn_val(g)), | 2888 | ZigLLVMBuildCall(g->builder, LLVMGlobalGetValueType(get_merge_err_ret_traces_fn_val(g)), |
| 2889 | get_merge_err_ret_traces_fn_val(g), args, 2, | 2889 | get_merge_err_ret_traces_fn_val(g), args, 2, |
| 2890 | get_llvm_cc(g, CallingConventionUnspecified), ZigLLVM_CallAttrAuto, ""); | 2890 | get_llvm_cc(g, CallingConventionUnspecified), ZigLLVM_CallAttrAuto, ""); |
| 2891 | } | 2891 | } |
| ... | @@ -3057,14 +3057,14 @@ static LLVMValueRef gen_soft_float_un_op(CodeGen *g, LLVMValueRef op, ZigType *o | ... | @@ -3057,14 +3057,14 @@ static LLVMValueRef gen_soft_float_un_op(CodeGen *g, LLVMValueRef op, ZigType *o |
| 3057 | LLVMValueRef func_ref = get_soft_float_fn(g, fn_name, 1, scalar_type->llvm_type, scalar_type->llvm_type); | 3057 | LLVMValueRef func_ref = get_soft_float_fn(g, fn_name, 1, scalar_type->llvm_type, scalar_type->llvm_type); |
| 3058 | | 3058 | |
| 3059 | if (vector_len == 0) { | 3059 | if (vector_len == 0) { |
| 3060 | return LLVMBuildCall2(g->builder, LLVMTypeOf(func_ref), func_ref, &op, 1, ""); | 3060 | return LLVMBuildCall2(g->builder, LLVMGlobalGetValueType(func_ref), func_ref, &op, 1, ""); |
| 3061 | } else { | 3061 | } else { |
| 3062 | LLVMValueRef result = LLVMGetUndef(operand_type->llvm_type); | 3062 | LLVMValueRef result = LLVMGetUndef(operand_type->llvm_type); |
| 3063 | LLVMTypeRef usize_ref = g->builtin_types.entry_usize->llvm_type; | 3063 | LLVMTypeRef usize_ref = g->builtin_types.entry_usize->llvm_type; |
| 3064 | for (uint32_t i = 0; i < vector_len; i++) { | 3064 | for (uint32_t i = 0; i < vector_len; i++) { |
| 3065 | LLVMValueRef index_value = LLVMConstInt(usize_ref, i, false); | 3065 | LLVMValueRef index_value = LLVMConstInt(usize_ref, i, false); |
| 3066 | LLVMValueRef param = LLVMBuildExtractElement(g->builder, op, index_value, ""); | 3066 | LLVMValueRef param = LLVMBuildExtractElement(g->builder, op, index_value, ""); |
| 3067 | LLVMValueRef call_result = LLVMBuildCall2(g->builder, LLVMTypeOf(func_ref), func_ref, &param, 1, ""); | 3067 | LLVMValueRef call_result = LLVMBuildCall2(g->builder, LLVMGlobalGetValueType(func_ref), func_ref, &param, 1, ""); |
| 3068 | result = LLVMBuildInsertElement(g->builder, result, call_result, index_value, ""); | 3068 | result = LLVMBuildInsertElement(g->builder, result, call_result, index_value, ""); |
| 3069 | } | 3069 | } |
| 3070 | return result; | 3070 | return result; |
| ... | @@ -3081,7 +3081,7 @@ static LLVMValueRef gen_float_un_op(CodeGen *g, LLVMValueRef operand, ZigType *o | ... | @@ -3081,7 +3081,7 @@ static LLVMValueRef gen_float_un_op(CodeGen *g, LLVMValueRef operand, ZigType *o |
| 3081 | return gen_soft_float_un_op(g, operand, operand_type, op); | 3081 | return gen_soft_float_un_op(g, operand, operand_type, op); |
| 3082 | } | 3082 | } |
| 3083 | LLVMValueRef float_op_fn = get_float_fn(g, operand_type, ZigLLVMFnIdFloatOp, op); | 3083 | LLVMValueRef float_op_fn = get_float_fn(g, operand_type, ZigLLVMFnIdFloatOp, op); |
| 3084 | return LLVMBuildCall2(g->builder, LLVMTypeOf(float_op_fn), float_op_fn, &operand, 1, ""); | 3084 | return LLVMBuildCall2(g->builder, LLVMGlobalGetValueType(float_op_fn), float_op_fn, &operand, 1, ""); |
| 3085 | } | 3085 | } |
| 3086 | | 3086 | |
| 3087 | enum DivKind { | 3087 | enum DivKind { |
| ... | @@ -3447,7 +3447,7 @@ static LLVMValueRef gen_soft_int_to_float_op(CodeGen *g, LLVMValueRef value_ref, | ... | @@ -3447,7 +3447,7 @@ static LLVMValueRef gen_soft_int_to_float_op(CodeGen *g, LLVMValueRef value_ref, |
| 3447 | } | 3447 | } |
| 3448 | | 3448 | |
| 3449 | LLVMValueRef params[1] = {value_ref}; | 3449 | LLVMValueRef params[1] = {value_ref}; |
| 3450 | return LLVMBuildCall2(g->builder, LLVMTypeOf(func_ref), func_ref, params, param_count, ""); | 3450 | return LLVMBuildCall2(g->builder, LLVMGlobalGetValueType(func_ref), func_ref, params, param_count, ""); |
| 3451 | } | 3451 | } |
| 3452 | | 3452 | |
| 3453 | static LLVMValueRef gen_soft_float_to_int_op(CodeGen *g, LLVMValueRef value_ref, ZigType *operand_type, ZigType *result_type) { | 3453 | static LLVMValueRef gen_soft_float_to_int_op(CodeGen *g, LLVMValueRef value_ref, ZigType *operand_type, ZigType *result_type) { |
| ... | @@ -3483,7 +3483,7 @@ static LLVMValueRef gen_soft_float_to_int_op(CodeGen *g, LLVMValueRef value_ref, | ... | @@ -3483,7 +3483,7 @@ static LLVMValueRef gen_soft_float_to_int_op(CodeGen *g, LLVMValueRef value_ref, |
| 3483 | } | 3483 | } |
| 3484 | | 3484 | |
| 3485 | LLVMValueRef params[1] = {value_ref}; | 3485 | LLVMValueRef params[1] = {value_ref}; |
| 3486 | LLVMValueRef result = LLVMBuildCall2(g->builder, LLVMTypeOf(func_ref), func_ref, params, param_count, ""); | 3486 | LLVMValueRef result = LLVMBuildCall2(g->builder, LLVMGlobalGetValueType(func_ref), func_ref, params, param_count, ""); |
| 3487 | | 3487 | |
| 3488 | if ((wider_type->data.integral.bit_count == 128) && (g->zig_target->os == OsWindows) && (g->zig_target->arch == ZigLLVM_x86_64)) { | 3488 | if ((wider_type->data.integral.bit_count == 128) && (g->zig_target->os == OsWindows) && (g->zig_target->arch == ZigLLVM_x86_64)) { |
| 3489 | result = LLVMBuildBitCast(g->builder, result, wider_type->llvm_type, ""); | 3489 | result = LLVMBuildBitCast(g->builder, result, wider_type->llvm_type, ""); |
| ... | @@ -3596,7 +3596,7 @@ static LLVMValueRef gen_soft_float_bin_op(CodeGen *g, LLVMValueRef op1_value, LL | ... | @@ -3596,7 +3596,7 @@ static LLVMValueRef gen_soft_float_bin_op(CodeGen *g, LLVMValueRef op1_value, LL |
| 3596 | LLVMValueRef result; | 3596 | LLVMValueRef result; |
| 3597 | if (vector_len == 0) { | 3597 | if (vector_len == 0) { |
| 3598 | LLVMValueRef params[2] = {op1_value, op2_value}; | 3598 | LLVMValueRef params[2] = {op1_value, op2_value}; |
| 3599 | result = LLVMBuildCall2(g->builder, LLVMTypeOf(func_ref), func_ref, params, param_count, ""); | 3599 | result = LLVMBuildCall2(g->builder, LLVMGlobalGetValueType(func_ref), func_ref, params, param_count, ""); |
| 3600 | result = add_icmp(g, result, res_icmp); | 3600 | result = add_icmp(g, result, res_icmp); |
| 3601 | } else { | 3601 | } else { |
| 3602 | ZigType *alloca_ty = operand_type; | 3602 | ZigType *alloca_ty = operand_type; |
| ... | @@ -3610,7 +3610,7 @@ static LLVMValueRef gen_soft_float_bin_op(CodeGen *g, LLVMValueRef op1_value, LL | ... | @@ -3610,7 +3610,7 @@ static LLVMValueRef gen_soft_float_bin_op(CodeGen *g, LLVMValueRef op1_value, LL |
| 3610 | LLVMBuildExtractElement(g->builder, op1_value, index_value, ""), | 3610 | LLVMBuildExtractElement(g->builder, op1_value, index_value, ""), |
| 3611 | LLVMBuildExtractElement(g->builder, op2_value, index_value, ""), | 3611 | LLVMBuildExtractElement(g->builder, op2_value, index_value, ""), |
| 3612 | }; | 3612 | }; |
| 3613 | LLVMValueRef call_result = LLVMBuildCall2(g->builder, LLVMTypeOf(func_ref), func_ref, params, param_count, ""); | 3613 | LLVMValueRef call_result = LLVMBuildCall2(g->builder, LLVMGlobalGetValueType(func_ref), func_ref, params, param_count, ""); |
| 3614 | call_result = add_icmp(g, call_result, res_icmp); | 3614 | call_result = add_icmp(g, call_result, res_icmp); |
| 3615 | result = LLVMBuildInsertElement(g->builder, result, call_result, index_value, ""); | 3615 | result = LLVMBuildInsertElement(g->builder, result, call_result, index_value, ""); |
| 3616 | } | 3616 | } |
| ... | @@ -4585,7 +4585,7 @@ static LLVMValueRef gen_valgrind_client_request(CodeGen *g, LLVMValueRef default | ... | @@ -4585,7 +4585,7 @@ static LLVMValueRef gen_valgrind_client_request(CodeGen *g, LLVMValueRef default |
| 4585 | LLVMValueRef asm_fn = LLVMGetInlineAsm(function_type, buf_ptr(asm_template), buf_len(asm_template), | 4585 | LLVMValueRef asm_fn = LLVMGetInlineAsm(function_type, buf_ptr(asm_template), buf_len(asm_template), |
| 4586 | buf_ptr(asm_constraints), buf_len(asm_constraints), asm_has_side_effects, asm_is_alignstack, | 4586 | buf_ptr(asm_constraints), buf_len(asm_constraints), asm_has_side_effects, asm_is_alignstack, |
| 4587 | LLVMInlineAsmDialectATT, false); | 4587 | LLVMInlineAsmDialectATT, false); |
| 4588 | return LLVMBuildCall2(g->builder, LLVMTypeOf(asm_fn), asm_fn, param_values, input_and_output_count, ""); | 4588 | return LLVMBuildCall2(g->builder, LLVMGlobalGetValueType(asm_fn), asm_fn, param_values, input_and_output_count, ""); |
| 4589 | } | 4589 | } |
| 4590 | } | 4590 | } |
| 4591 | zig_unreachable(); | 4591 | zig_unreachable(); |
| ... | @@ -4849,7 +4849,7 @@ static void gen_set_stack_pointer(CodeGen *g, LLVMValueRef aligned_end_addr) { | ... | @@ -4849,7 +4849,7 @@ static void gen_set_stack_pointer(CodeGen *g, LLVMValueRef aligned_end_addr) { |
| 4849 | aligned_end_addr, | 4849 | aligned_end_addr, |
| 4850 | }; | 4850 | }; |
| 4851 | | 4851 | |
| 4852 | LLVMBuildCall2(g->builder, LLVMTypeOf(write_register_fn_val), write_register_fn_val, params, 2, ""); | 4852 | LLVMBuildCall2(g->builder, LLVMGlobalGetValueType(write_register_fn_val), write_register_fn_val, params, 2, ""); |
| 4853 | } | 4853 | } |
| 4854 | | 4854 | |
| 4855 | static void render_async_spills(CodeGen *g) { | 4855 | static void render_async_spills(CodeGen *g) { |
| ... | @@ -4996,10 +4996,6 @@ static LLVMValueRef ir_render_call(CodeGen *g, Stage1Air *executable, Stage1AirI | ... | @@ -4996,10 +4996,6 @@ static LLVMValueRef ir_render_call(CodeGen *g, Stage1Air *executable, Stage1AirI |
| 4996 | callee_is_async = fn_type->data.fn.fn_type_id.cc == CallingConventionAsync; | 4996 | callee_is_async = fn_type->data.fn.fn_type_id.cc == CallingConventionAsync; |
| 4997 | } | 4997 | } |
| 4998 | | 4998 | |
| 4999 | LLVMTypeRef frame_struct_llvm_ty = (instruction->fn_entry != nullptr) ? | | |
| 5000 | get_llvm_type(g, get_fn_frame_type(g, instruction->fn_entry)) : | | |
| 5001 | g->any_frame_header_llvm_ty; | | |
| 5002 | | | |
| 5003 | FnTypeId *fn_type_id = &fn_type->data.fn.fn_type_id; | 4999 | FnTypeId *fn_type_id = &fn_type->data.fn.fn_type_id; |
| 5004 | | 5000 | |
| 5005 | ZigType *src_return_type = fn_type_id->return_type; | 5001 | ZigType *src_return_type = fn_type_id->return_type; |
| ... | @@ -5018,23 +5014,33 @@ static LLVMValueRef ir_render_call(CodeGen *g, Stage1Air *executable, Stage1AirI | ... | @@ -5018,23 +5014,33 @@ static LLVMValueRef ir_render_call(CodeGen *g, Stage1Air *executable, Stage1AirI |
| 5018 | ZigType *anyframe_type = nullptr; | 5014 | ZigType *anyframe_type = nullptr; |
| 5019 | LLVMValueRef frame_result_loc_uncasted = nullptr; | 5015 | LLVMValueRef frame_result_loc_uncasted = nullptr; |
| 5020 | LLVMValueRef frame_result_loc; | 5016 | LLVMValueRef frame_result_loc; |
| | 5017 | LLVMTypeRef frame_struct_llvm_ty; |
| 5021 | LLVMValueRef awaiter_init_val; | 5018 | LLVMValueRef awaiter_init_val; |
| 5022 | LLVMValueRef ret_ptr; | 5019 | LLVMValueRef ret_ptr; |
| 5023 | if (callee_is_async) { | 5020 | if (callee_is_async) { |
| 5024 | if (instruction->new_stack == nullptr) { | 5021 | if (instruction->new_stack == nullptr) { |
| 5025 | if (instruction->modifier == CallModifierAsync) { | 5022 | if (instruction->modifier == CallModifierAsync) { |
| 5026 | frame_result_loc = result_loc; | 5023 | frame_result_loc = result_loc; |
| | 5024 | if (result_loc != nullptr) { |
| | 5025 | ir_assert(instruction->result_loc->value->type->id == ZigTypeIdPointer, &instruction->base); |
| | 5026 | frame_struct_llvm_ty = get_llvm_type(g, instruction->result_loc->value->type->data.pointer.child_type); |
| | 5027 | } else { |
| | 5028 | frame_struct_llvm_ty = nullptr; |
| | 5029 | } |
| 5027 | } else { | 5030 | } else { |
| 5028 | ir_assert(instruction->frame_result_loc != nullptr, &instruction->base); | 5031 | ir_assert(instruction->frame_result_loc != nullptr, &instruction->base); |
| 5029 | frame_result_loc_uncasted = ir_llvm_value(g, instruction->frame_result_loc); | 5032 | frame_result_loc_uncasted = ir_llvm_value(g, instruction->frame_result_loc); |
| 5030 | ir_assert(instruction->fn_entry != nullptr, &instruction->base); | 5033 | ir_assert(instruction->fn_entry != nullptr, &instruction->base); |
| 5031 | frame_result_loc = frame_result_loc_uncasted; | 5034 | frame_struct_llvm_ty = get_llvm_type(g, instruction->fn_entry->frame_type); |
| | 5035 | frame_result_loc = LLVMBuildBitCast(g->builder, frame_result_loc_uncasted, |
| | 5036 | LLVMPointerType(frame_struct_llvm_ty, 0), ""); |
| 5032 | } | 5037 | } |
| 5033 | } else { | 5038 | } else { |
| 5034 | if (instruction->new_stack->value->type->id == ZigTypeIdPointer && | 5039 | if (instruction->new_stack->value->type->id == ZigTypeIdPointer && |
| 5035 | instruction->new_stack->value->type->data.pointer.child_type->id == ZigTypeIdFnFrame) | 5040 | instruction->new_stack->value->type->data.pointer.child_type->id == ZigTypeIdFnFrame) |
| 5036 | { | 5041 | { |
| 5037 | frame_result_loc = ir_llvm_value(g, instruction->new_stack); | 5042 | frame_result_loc = ir_llvm_value(g, instruction->new_stack); |
| | 5043 | frame_struct_llvm_ty = get_llvm_type(g, instruction->new_stack->value->type->data.pointer.child_type); |
| 5038 | } else { | 5044 | } else { |
| 5039 | LLVMValueRef frame_slice_ptr = ir_llvm_value(g, instruction->new_stack); | 5045 | LLVMValueRef frame_slice_ptr = ir_llvm_value(g, instruction->new_stack); |
| 5040 | LLVMTypeRef frame_slice_llvm_ty = | 5046 | LLVMTypeRef frame_slice_llvm_ty = |
| ... | @@ -5063,12 +5069,16 @@ static LLVMValueRef ir_render_call(CodeGen *g, Stage1Air *executable, Stage1AirI | ... | @@ -5063,12 +5069,16 @@ static LLVMValueRef ir_render_call(CodeGen *g, Stage1Air *executable, Stage1AirI |
| 5063 | LLVMGetGEPSourceElementType(frame_ptr_ptr), frame_ptr_ptr, ""); | 5069 | LLVMGetGEPSourceElementType(frame_ptr_ptr), frame_ptr_ptr, ""); |
| 5064 | if (instruction->fn_entry == nullptr) { | 5070 | if (instruction->fn_entry == nullptr) { |
| 5065 | anyframe_type = get_any_frame_type(g, src_return_type); | 5071 | anyframe_type = get_any_frame_type(g, src_return_type); |
| 5066 | frame_result_loc = frame_ptr; | 5072 | frame_result_loc = LLVMBuildBitCast(g->builder, frame_ptr, get_llvm_type(g, anyframe_type), ""); |
| | 5073 | frame_struct_llvm_ty = g->any_frame_header_llvm_ty; |
| 5067 | } else { | 5074 | } else { |
| 5068 | ZigType *frame_type = get_fn_frame_type(g, instruction->fn_entry); | 5075 | ZigType *frame_type = get_fn_frame_type(g, instruction->fn_entry); |
| 5069 | if ((err = type_resolve(g, frame_type, ResolveStatusLLVMFull))) | 5076 | if ((err = type_resolve(g, frame_type, ResolveStatusLLVMFull))) |
| 5070 | codegen_report_errors_and_exit(g); | 5077 | codegen_report_errors_and_exit(g); |
| 5071 | frame_result_loc = frame_ptr; | 5078 | ZigType *ptr_frame_type = get_pointer_to_type(g, frame_type, false); |
| | 5079 | frame_result_loc = LLVMBuildBitCast(g->builder, frame_ptr, |
| | 5080 | get_llvm_type(g, ptr_frame_type), ""); |
| | 5081 | frame_struct_llvm_ty = get_llvm_type(g, frame_type); |
| 5072 | } | 5082 | } |
| 5073 | } | 5083 | } |
| 5074 | } | 5084 | } |
| ... | @@ -5156,6 +5166,12 @@ static LLVMValueRef ir_render_call(CodeGen *g, Stage1Air *executable, Stage1AirI | ... | @@ -5156,6 +5166,12 @@ static LLVMValueRef ir_render_call(CodeGen *g, Stage1Air *executable, Stage1AirI |
| 5156 | zig_panic("TODO @asyncCall of non-async function"); | 5166 | zig_panic("TODO @asyncCall of non-async function"); |
| 5157 | } | 5167 | } |
| 5158 | frame_result_loc = result_loc; | 5168 | frame_result_loc = result_loc; |
| | 5169 | if (result_loc != nullptr) { |
| | 5170 | ir_assert(instruction->result_loc->value->type->id == ZigTypeIdPointer, &instruction->base); |
| | 5171 | frame_struct_llvm_ty = get_llvm_type(g, instruction->result_loc->value->type->data.pointer.child_type); |
| | 5172 | } else { |
| | 5173 | frame_struct_llvm_ty = nullptr; |
| | 5174 | } |
| 5159 | awaiter_init_val = LLVMConstAllOnes(usize_type_ref); | 5175 | awaiter_init_val = LLVMConstAllOnes(usize_type_ref); |
| 5160 | | 5176 | |
| 5161 | LLVMValueRef awaiter_ptr = LLVMBuildStructGEP2(g->builder, frame_struct_llvm_ty, frame_result_loc, frame_awaiter_index, ""); | 5177 | LLVMValueRef awaiter_ptr = LLVMBuildStructGEP2(g->builder, frame_struct_llvm_ty, frame_result_loc, frame_awaiter_index, ""); |
| ... | @@ -5352,11 +5368,13 @@ static LLVMValueRef ir_render_call(CodeGen *g, Stage1Air *executable, Stage1AirI | ... | @@ -5352,11 +5368,13 @@ static LLVMValueRef ir_render_call(CodeGen *g, Stage1Air *executable, Stage1AirI |
| 5352 | } | 5368 | } |
| 5353 | if (frame_result_loc_uncasted != nullptr) { | 5369 | if (frame_result_loc_uncasted != nullptr) { |
| 5354 | if (instruction->fn_entry != nullptr) { | 5370 | if (instruction->fn_entry != nullptr) { |
| | 5371 | frame_struct_llvm_ty = get_llvm_type(g, instruction->fn_entry->frame_type); |
| 5355 | frame_result_loc = LLVMBuildBitCast(g->builder, frame_result_loc_uncasted, | 5372 | frame_result_loc = LLVMBuildBitCast(g->builder, frame_result_loc_uncasted, |
| 5356 | LLVMPointerType(get_llvm_type(g, instruction->fn_entry->frame_type), 0), ""); | 5373 | LLVMPointerType(frame_struct_llvm_ty, 0), ""); |
| 5357 | } else { | 5374 | } else { |
| 5358 | frame_result_loc = LLVMBuildBitCast(g->builder, frame_result_loc_uncasted, | 5375 | frame_result_loc = LLVMBuildBitCast(g->builder, frame_result_loc_uncasted, |
| 5359 | get_llvm_type(g, anyframe_type), ""); | 5376 | get_llvm_type(g, anyframe_type), ""); |
| | 5377 | frame_struct_llvm_ty = g->any_frame_header_llvm_ty; |
| 5360 | } | 5378 | } |
| 5361 | } | 5379 | } |
| 5362 | | 5380 | |
| ... | @@ -5369,7 +5387,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, Stage1Air *executable, Stage1AirI | ... | @@ -5369,7 +5387,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, Stage1Air *executable, Stage1AirI |
| 5369 | } | 5387 | } |
| 5370 | | 5388 | |
| 5371 | if (instruction->new_stack == nullptr || instruction->is_async_call_builtin) { | 5389 | if (instruction->new_stack == nullptr || instruction->is_async_call_builtin) { |
| 5372 | result = ZigLLVMBuildCall(g->builder, LLVMTypeOf(fn_val), fn_val, | 5390 | result = ZigLLVMBuildCall(g->builder, LLVMGlobalGetValueType(fn_val), fn_val, |
| 5373 | gen_param_values.items, (unsigned)gen_param_values.length, llvm_cc, call_attr, ""); | 5391 | gen_param_values.items, (unsigned)gen_param_values.length, llvm_cc, call_attr, ""); |
| 5374 | } else if (instruction->modifier == CallModifierAsync) { | 5392 | } else if (instruction->modifier == CallModifierAsync) { |
| 5375 | zig_panic("TODO @asyncCall of non-async function"); | 5393 | zig_panic("TODO @asyncCall of non-async function"); |
| ... | @@ -5380,14 +5398,14 @@ static LLVMValueRef ir_render_call(CodeGen *g, Stage1Air *executable, Stage1AirI | ... | @@ -5380,14 +5398,14 @@ static LLVMValueRef ir_render_call(CodeGen *g, Stage1Air *executable, Stage1AirI |
| 5380 | LLVMValueRef old_stack_ref; | 5398 | LLVMValueRef old_stack_ref; |
| 5381 | if (src_return_type->id != ZigTypeIdUnreachable) { | 5399 | if (src_return_type->id != ZigTypeIdUnreachable) { |
| 5382 | LLVMValueRef stacksave_fn_val = get_stacksave_fn_val(g); | 5400 | LLVMValueRef stacksave_fn_val = get_stacksave_fn_val(g); |
| 5383 | old_stack_ref = LLVMBuildCall2(g->builder, LLVMTypeOf(stacksave_fn_val), stacksave_fn_val, nullptr, 0, ""); | 5401 | old_stack_ref = LLVMBuildCall2(g->builder, LLVMGlobalGetValueType(stacksave_fn_val), stacksave_fn_val, nullptr, 0, ""); |
| 5384 | } | 5402 | } |
| 5385 | gen_set_stack_pointer(g, new_stack_addr); | 5403 | gen_set_stack_pointer(g, new_stack_addr); |
| 5386 | result = ZigLLVMBuildCall(g->builder, LLVMTypeOf(fn_val), fn_val, | 5404 | result = ZigLLVMBuildCall(g->builder, LLVMGlobalGetValueType(fn_val), fn_val, |
| 5387 | gen_param_values.items, (unsigned)gen_param_values.length, llvm_cc, call_attr, ""); | 5405 | gen_param_values.items, (unsigned)gen_param_values.length, llvm_cc, call_attr, ""); |
| 5388 | if (src_return_type->id != ZigTypeIdUnreachable) { | 5406 | if (src_return_type->id != ZigTypeIdUnreachable) { |
| 5389 | LLVMValueRef stackrestore_fn_val = get_stackrestore_fn_val(g); | 5407 | LLVMValueRef stackrestore_fn_val = get_stackrestore_fn_val(g); |
| 5390 | LLVMBuildCall2(g->builder, LLVMTypeOf(stackrestore_fn_val), stackrestore_fn_val, &old_stack_ref, 1, ""); | 5408 | LLVMBuildCall2(g->builder, LLVMGlobalGetValueType(stackrestore_fn_val), stackrestore_fn_val, &old_stack_ref, 1, ""); |
| 5391 | } | 5409 | } |
| 5392 | } | 5410 | } |
| 5393 | | 5411 | |
| ... | @@ -5735,7 +5753,7 @@ static LLVMValueRef ir_render_asm_gen(CodeGen *g, Stage1Air *executable, Stage1A | ... | @@ -5735,7 +5753,7 @@ static LLVMValueRef ir_render_asm_gen(CodeGen *g, Stage1Air *executable, Stage1A |
| 5735 | LLVMValueRef asm_fn = LLVMGetInlineAsm(function_type, buf_ptr(&llvm_template), buf_len(&llvm_template), | 5753 | LLVMValueRef asm_fn = LLVMGetInlineAsm(function_type, buf_ptr(&llvm_template), buf_len(&llvm_template), |
| 5736 | buf_ptr(&constraint_buf), buf_len(&constraint_buf), is_volatile, false, LLVMInlineAsmDialectATT, false); | 5754 | buf_ptr(&constraint_buf), buf_len(&constraint_buf), is_volatile, false, LLVMInlineAsmDialectATT, false); |
| 5737 | | 5755 | |
| 5738 | LLVMValueRef built_call = LLVMBuildCall2(g->builder, LLVMTypeOf(asm_fn), asm_fn, param_values, (unsigned)input_and_output_count, ""); | 5756 | LLVMValueRef built_call = LLVMBuildCall2(g->builder, LLVMGlobalGetValueType(asm_fn), asm_fn, param_values, (unsigned)input_and_output_count, ""); |
| 5739 | | 5757 | |
| 5740 | for (size_t i = 0; i < input_and_output_count; i += 1) { | 5758 | for (size_t i = 0; i < input_and_output_count; i += 1) { |
| 5741 | if (param_needs_attr[i]) { | 5759 | if (param_needs_attr[i]) { |
| ... | @@ -5895,7 +5913,7 @@ static LLVMValueRef ir_render_clz(CodeGen *g, Stage1Air *executable, Stage1AirIn | ... | @@ -5895,7 +5913,7 @@ static LLVMValueRef ir_render_clz(CodeGen *g, Stage1Air *executable, Stage1AirIn |
| 5895 | operand, | 5913 | operand, |
| 5896 | LLVMConstNull(LLVMInt1Type()), | 5914 | LLVMConstNull(LLVMInt1Type()), |
| 5897 | }; | 5915 | }; |
| 5898 | LLVMValueRef wrong_size_int = LLVMBuildCall2(g->builder, LLVMTypeOf(fn_val), fn_val, params, 2, ""); | 5916 | LLVMValueRef wrong_size_int = LLVMBuildCall2(g->builder, LLVMGlobalGetValueType(fn_val), fn_val, params, 2, ""); |
| 5899 | return gen_widen_or_shorten(g, false, int_type, instruction->base.value->type, wrong_size_int); | 5917 | return gen_widen_or_shorten(g, false, int_type, instruction->base.value->type, wrong_size_int); |
| 5900 | } | 5918 | } |
| 5901 | | 5919 | |
| ... | @@ -5907,7 +5925,7 @@ static LLVMValueRef ir_render_ctz(CodeGen *g, Stage1Air *executable, Stage1AirIn | ... | @@ -5907,7 +5925,7 @@ static LLVMValueRef ir_render_ctz(CodeGen *g, Stage1Air *executable, Stage1AirIn |
| 5907 | operand, | 5925 | operand, |
| 5908 | LLVMConstNull(LLVMInt1Type()), | 5926 | LLVMConstNull(LLVMInt1Type()), |
| 5909 | }; | 5927 | }; |
| 5910 | LLVMValueRef wrong_size_int = LLVMBuildCall2(g->builder, LLVMTypeOf(fn_val), fn_val, params, 2, ""); | 5928 | LLVMValueRef wrong_size_int = LLVMBuildCall2(g->builder, LLVMGlobalGetValueType(fn_val), fn_val, params, 2, ""); |
| 5911 | return gen_widen_or_shorten(g, false, int_type, instruction->base.value->type, wrong_size_int); | 5929 | return gen_widen_or_shorten(g, false, int_type, instruction->base.value->type, wrong_size_int); |
| 5912 | } | 5930 | } |
| 5913 | | 5931 | |
| ... | @@ -5964,7 +5982,7 @@ static LLVMValueRef ir_render_pop_count(CodeGen *g, Stage1Air *executable, Stage | ... | @@ -5964,7 +5982,7 @@ static LLVMValueRef ir_render_pop_count(CodeGen *g, Stage1Air *executable, Stage |
| 5964 | ZigType *int_type = instruction->op->value->type; | 5982 | ZigType *int_type = instruction->op->value->type; |
| 5965 | LLVMValueRef fn_val = get_int_builtin_fn(g, int_type, BuiltinFnIdPopCount); | 5983 | LLVMValueRef fn_val = get_int_builtin_fn(g, int_type, BuiltinFnIdPopCount); |
| 5966 | LLVMValueRef operand = ir_llvm_value(g, instruction->op); | 5984 | LLVMValueRef operand = ir_llvm_value(g, instruction->op); |
| 5967 | LLVMValueRef wrong_size_int = LLVMBuildCall2(g->builder, LLVMTypeOf(fn_val), fn_val, &operand, 1, ""); | 5985 | LLVMValueRef wrong_size_int = LLVMBuildCall2(g->builder, LLVMGlobalGetValueType(fn_val), fn_val, &operand, 1, ""); |
| 5968 | return gen_widen_or_shorten(g, false, int_type, instruction->base.value->type, wrong_size_int); | 5986 | return gen_widen_or_shorten(g, false, int_type, instruction->base.value->type, wrong_size_int); |
| 5969 | } | 5987 | } |
| 5970 | | 5988 | |
| ... | @@ -6180,7 +6198,7 @@ static LLVMValueRef ir_render_enum_tag_name(CodeGen *g, Stage1Air *executable, | ... | @@ -6180,7 +6198,7 @@ static LLVMValueRef ir_render_enum_tag_name(CodeGen *g, Stage1Air *executable, |
| 6180 | LLVMValueRef enum_name_function = get_enum_tag_name_function(g, enum_type); | 6198 | LLVMValueRef enum_name_function = get_enum_tag_name_function(g, enum_type); |
| 6181 | | 6199 | |
| 6182 | LLVMValueRef enum_tag_value = ir_llvm_value(g, instruction->target); | 6200 | LLVMValueRef enum_tag_value = ir_llvm_value(g, instruction->target); |
| 6183 | return ZigLLVMBuildCall(g->builder, LLVMTypeOf(enum_name_function), enum_name_function, | 6201 | return ZigLLVMBuildCall(g->builder, LLVMGlobalGetValueType(enum_name_function), enum_name_function, |
| 6184 | &enum_tag_value, 1, | 6202 | &enum_tag_value, 1, |
| 6185 | get_llvm_cc(g, CallingConventionUnspecified), ZigLLVM_CallAttrAuto, ""); | 6203 | get_llvm_cc(g, CallingConventionUnspecified), ZigLLVM_CallAttrAuto, ""); |
| 6186 | } | 6204 | } |
| ... | @@ -6557,7 +6575,7 @@ static LLVMValueRef ir_render_memcpy(CodeGen *g, Stage1Air *executable, Stage1Ai | ... | @@ -6557,7 +6575,7 @@ static LLVMValueRef ir_render_memcpy(CodeGen *g, Stage1Air *executable, Stage1Ai |
| 6557 | static LLVMValueRef ir_render_wasm_memory_size(CodeGen *g, Stage1Air *executable, Stage1AirInstWasmMemorySize *instruction) { | 6575 | static LLVMValueRef ir_render_wasm_memory_size(CodeGen *g, Stage1Air *executable, Stage1AirInstWasmMemorySize *instruction) { |
| 6558 | // TODO adjust for wasm64 | 6576 | // TODO adjust for wasm64 |
| 6559 | LLVMValueRef param = ir_llvm_value(g, instruction->index); | 6577 | LLVMValueRef param = ir_llvm_value(g, instruction->index); |
| 6560 | LLVMValueRef val = LLVMBuildCall2(g->builder, LLVMTypeOf(gen_wasm_memory_size(g)), gen_wasm_memory_size(g), &param, 1, ""); | 6578 | LLVMValueRef val = LLVMBuildCall2(g->builder, LLVMGlobalGetValueType(gen_wasm_memory_size(g)), gen_wasm_memory_size(g), &param, 1, ""); |
| 6561 | return val; | 6579 | return val; |
| 6562 | } | 6580 | } |
| 6563 | | 6581 | |
| ... | @@ -6567,7 +6585,7 @@ static LLVMValueRef ir_render_wasm_memory_grow(CodeGen *g, Stage1Air *executable | ... | @@ -6567,7 +6585,7 @@ static LLVMValueRef ir_render_wasm_memory_grow(CodeGen *g, Stage1Air *executable |
| 6567 | ir_llvm_value(g, instruction->index), | 6585 | ir_llvm_value(g, instruction->index), |
| 6568 | ir_llvm_value(g, instruction->delta), | 6586 | ir_llvm_value(g, instruction->delta), |
| 6569 | }; | 6587 | }; |
| 6570 | LLVMValueRef val = LLVMBuildCall2(g->builder, LLVMTypeOf(gen_wasm_memory_grow(g)), gen_wasm_memory_grow(g), params, 2, ""); | 6588 | LLVMValueRef val = LLVMBuildCall2(g->builder, LLVMGlobalGetValueType(gen_wasm_memory_grow(g)), gen_wasm_memory_grow(g), params, 2, ""); |
| 6571 | return val; | 6589 | return val; |
| 6572 | } | 6590 | } |
| 6573 | | 6591 | |
| ... | @@ -6613,7 +6631,7 @@ static LLVMValueRef ir_render_prefetch(CodeGen *g, Stage1Air *executable, Stage1 | ... | @@ -6613,7 +6631,7 @@ static LLVMValueRef ir_render_prefetch(CodeGen *g, Stage1Air *executable, Stage1 |
| 6613 | LLVMConstInt(LLVMInt32Type(), instruction->locality, false), | 6631 | LLVMConstInt(LLVMInt32Type(), instruction->locality, false), |
| 6614 | LLVMConstInt(LLVMInt32Type(), instruction->cache, false), | 6632 | LLVMConstInt(LLVMInt32Type(), instruction->cache, false), |
| 6615 | }; | 6633 | }; |
| 6616 | LLVMValueRef val = LLVMBuildCall2(g->builder, LLVMTypeOf(gen_prefetch(g)), gen_prefetch(g), params, 4, ""); | 6634 | LLVMValueRef val = LLVMBuildCall2(g->builder, LLVMGlobalGetValueType(gen_prefetch(g)), gen_prefetch(g), params, 4, ""); |
| 6617 | return val; | 6635 | return val; |
| 6618 | } | 6636 | } |
| 6619 | | 6637 | |
| ... | @@ -6868,7 +6886,7 @@ static LLVMValueRef get_trap_fn_val(CodeGen *g) { | ... | @@ -6868,7 +6886,7 @@ static LLVMValueRef get_trap_fn_val(CodeGen *g) { |
| 6868 | | 6886 | |
| 6869 | | 6887 | |
| 6870 | static LLVMValueRef ir_render_breakpoint(CodeGen *g, Stage1Air *executable, Stage1AirInstBreakpoint *instruction) { | 6888 | static LLVMValueRef ir_render_breakpoint(CodeGen *g, Stage1Air *executable, Stage1AirInstBreakpoint *instruction) { |
| 6871 | LLVMBuildCall2(g->builder, LLVMTypeOf(get_trap_fn_val(g)), get_trap_fn_val(g), nullptr, 0, ""); | 6889 | LLVMBuildCall2(g->builder, LLVMGlobalGetValueType(get_trap_fn_val(g)), get_trap_fn_val(g), nullptr, 0, ""); |
| 6872 | return nullptr; | 6890 | return nullptr; |
| 6873 | } | 6891 | } |
| 6874 | | 6892 | |
| ... | @@ -6882,7 +6900,7 @@ static LLVMValueRef ir_render_return_address(CodeGen *g, Stage1Air *executable, | ... | @@ -6882,7 +6900,7 @@ static LLVMValueRef ir_render_return_address(CodeGen *g, Stage1Air *executable, |
| 6882 | } | 6900 | } |
| 6883 | | 6901 | |
| 6884 | LLVMValueRef zero = LLVMConstNull(g->builtin_types.entry_i32->llvm_type); | 6902 | LLVMValueRef zero = LLVMConstNull(g->builtin_types.entry_i32->llvm_type); |
| 6885 | LLVMValueRef ptr_val = LLVMBuildCall2(g->builder, LLVMTypeOf(get_return_address_fn_val(g)), get_return_address_fn_val(g), &zero, 1, ""); | 6903 | LLVMValueRef ptr_val = LLVMBuildCall2(g->builder, LLVMGlobalGetValueType(get_return_address_fn_val(g)), get_return_address_fn_val(g), &zero, 1, ""); |
| 6886 | return LLVMBuildPtrToInt(g->builder, ptr_val, g->builtin_types.entry_usize->llvm_type, ""); | 6904 | return LLVMBuildPtrToInt(g->builder, ptr_val, g->builtin_types.entry_usize->llvm_type, ""); |
| 6887 | } | 6905 | } |
| 6888 | | 6906 | |
| ... | @@ -6904,7 +6922,7 @@ static LLVMValueRef ir_render_frame_address(CodeGen *g, Stage1Air *executable, | ... | @@ -6904,7 +6922,7 @@ static LLVMValueRef ir_render_frame_address(CodeGen *g, Stage1Air *executable, |
| 6904 | Stage1AirInstFrameAddress *instruction) | 6922 | Stage1AirInstFrameAddress *instruction) |
| 6905 | { | 6923 | { |
| 6906 | LLVMValueRef zero = LLVMConstNull(g->builtin_types.entry_i32->llvm_type); | 6924 | LLVMValueRef zero = LLVMConstNull(g->builtin_types.entry_i32->llvm_type); |
| 6907 | LLVMValueRef ptr_val = LLVMBuildCall2(g->builder, LLVMTypeOf(get_frame_address_fn_val(g)), get_frame_address_fn_val(g), &zero, 1, ""); | 6925 | LLVMValueRef ptr_val = LLVMBuildCall2(g->builder, LLVMGlobalGetValueType(get_frame_address_fn_val(g)), get_frame_address_fn_val(g), &zero, 1, ""); |
| 6908 | return LLVMBuildPtrToInt(g->builder, ptr_val, g->builtin_types.entry_usize->llvm_type, ""); | 6926 | return LLVMBuildPtrToInt(g->builder, ptr_val, g->builtin_types.entry_usize->llvm_type, ""); |
| 6909 | } | 6927 | } |
| 6910 | | 6928 | |
| ... | @@ -6967,7 +6985,7 @@ static LLVMValueRef ir_render_overflow_op(CodeGen *g, Stage1Air *executable, Sta | ... | @@ -6967,7 +6985,7 @@ static LLVMValueRef ir_render_overflow_op(CodeGen *g, Stage1Air *executable, Sta |
| 6967 | op2, | 6985 | op2, |
| 6968 | }; | 6986 | }; |
| 6969 | | 6987 | |
| 6970 | LLVMValueRef result_struct = LLVMBuildCall2(g->builder, LLVMTypeOf(fn_val), fn_val, params, 2, ""); | 6988 | LLVMValueRef result_struct = LLVMBuildCall2(g->builder, LLVMGlobalGetValueType(fn_val), fn_val, params, 2, ""); |
| 6971 | LLVMValueRef result = LLVMBuildExtractValue(g->builder, result_struct, 0, ""); | 6989 | LLVMValueRef result = LLVMBuildExtractValue(g->builder, result_struct, 0, ""); |
| 6972 | LLVMValueRef overflow_bit = LLVMBuildExtractValue(g->builder, result_struct, 1, ""); | 6990 | LLVMValueRef overflow_bit = LLVMBuildExtractValue(g->builder, result_struct, 1, ""); |
| 6973 | gen_store(g, result, ptr_result, instruction->result_ptr->value->type); | 6991 | gen_store(g, result, ptr_result, instruction->result_ptr->value->type); |
| ... | @@ -7339,7 +7357,7 @@ static LLVMValueRef ir_render_soft_mul_add(CodeGen *g, Stage1Air *executable, St | ... | @@ -7339,7 +7357,7 @@ static LLVMValueRef ir_render_soft_mul_add(CodeGen *g, Stage1Air *executable, St |
| 7339 | LLVMValueRef op3 = ir_llvm_value(g, instruction->op3); | 7357 | LLVMValueRef op3 = ir_llvm_value(g, instruction->op3); |
| 7340 | if (vector_len == 0) { | 7358 | if (vector_len == 0) { |
| 7341 | LLVMValueRef params[3] = { op1, op2, op3 }; | 7359 | LLVMValueRef params[3] = { op1, op2, op3 }; |
| 7342 | return LLVMBuildCall2(g->builder, LLVMTypeOf(func_ref), func_ref, params, 3, ""); | 7360 | return LLVMBuildCall2(g->builder, LLVMGlobalGetValueType(func_ref), func_ref, params, 3, ""); |
| 7343 | } | 7361 | } |
| 7344 | | 7362 | |
| 7345 | LLVMValueRef result = LLVMGetUndef(get_llvm_type(g, instruction->op1->value->type)); | 7363 | LLVMValueRef result = LLVMGetUndef(get_llvm_type(g, instruction->op1->value->type)); |
| ... | @@ -7352,7 +7370,7 @@ static LLVMValueRef ir_render_soft_mul_add(CodeGen *g, Stage1Air *executable, St | ... | @@ -7352,7 +7370,7 @@ static LLVMValueRef ir_render_soft_mul_add(CodeGen *g, Stage1Air *executable, St |
| 7352 | LLVMBuildExtractElement(g->builder, op2, index_value, ""), | 7370 | LLVMBuildExtractElement(g->builder, op2, index_value, ""), |
| 7353 | LLVMBuildExtractElement(g->builder, op3, index_value, ""), | 7371 | LLVMBuildExtractElement(g->builder, op3, index_value, ""), |
| 7354 | }; | 7372 | }; |
| 7355 | LLVMValueRef call_result = LLVMBuildCall2(g->builder, LLVMTypeOf(func_ref), func_ref, params, 3, ""); | 7373 | LLVMValueRef call_result = LLVMBuildCall2(g->builder, LLVMGlobalGetValueType(func_ref), func_ref, params, 3, ""); |
| 7356 | result = LLVMBuildInsertElement(g->builder, result, call_result, index_value, ""); | 7374 | result = LLVMBuildInsertElement(g->builder, result, call_result, index_value, ""); |
| 7357 | } | 7375 | } |
| 7358 | return result; | 7376 | return result; |
| ... | @@ -7372,7 +7390,7 @@ static LLVMValueRef ir_render_mul_add(CodeGen *g, Stage1Air *executable, Stage1A | ... | @@ -7372,7 +7390,7 @@ static LLVMValueRef ir_render_mul_add(CodeGen *g, Stage1Air *executable, Stage1A |
| 7372 | instruction->base.value->type->id == ZigTypeIdVector); | 7390 | instruction->base.value->type->id == ZigTypeIdVector); |
| 7373 | LLVMValueRef fn_val = get_float_fn(g, instruction->base.value->type, ZigLLVMFnIdFMA, BuiltinFnIdMulAdd); | 7391 | LLVMValueRef fn_val = get_float_fn(g, instruction->base.value->type, ZigLLVMFnIdFMA, BuiltinFnIdMulAdd); |
| 7374 | LLVMValueRef args[3] = { op1, op2, op3 }; | 7392 | LLVMValueRef args[3] = { op1, op2, op3 }; |
| 7375 | return LLVMBuildCall2(g->builder, LLVMTypeOf(fn_val), fn_val, args, 3, ""); | 7393 | return LLVMBuildCall2(g->builder, LLVMGlobalGetValueType(fn_val), fn_val, args, 3, ""); |
| 7376 | } | 7394 | } |
| 7377 | | 7395 | |
| 7378 | static LLVMValueRef ir_render_bswap(CodeGen *g, Stage1Air *executable, Stage1AirInstBswap *instruction) { | 7396 | static LLVMValueRef ir_render_bswap(CodeGen *g, Stage1Air *executable, Stage1AirInstBswap *instruction) { |
| ... | @@ -7383,7 +7401,7 @@ static LLVMValueRef ir_render_bswap(CodeGen *g, Stage1Air *executable, Stage1Air | ... | @@ -7383,7 +7401,7 @@ static LLVMValueRef ir_render_bswap(CodeGen *g, Stage1Air *executable, Stage1Air |
| 7383 | assert(int_type->id == ZigTypeIdInt); | 7401 | assert(int_type->id == ZigTypeIdInt); |
| 7384 | if (int_type->data.integral.bit_count % 16 == 0) { | 7402 | if (int_type->data.integral.bit_count % 16 == 0) { |
| 7385 | LLVMValueRef fn_val = get_int_builtin_fn(g, expr_type, BuiltinFnIdBswap); | 7403 | LLVMValueRef fn_val = get_int_builtin_fn(g, expr_type, BuiltinFnIdBswap); |
| 7386 | return LLVMBuildCall2(g->builder, LLVMTypeOf(fn_val), fn_val, &op, 1, ""); | 7404 | return LLVMBuildCall2(g->builder, LLVMGlobalGetValueType(fn_val), fn_val, &op, 1, ""); |
| 7387 | } | 7405 | } |
| 7388 | // Not an even number of bytes, so we zext 1 byte, then bswap, shift right 1 byte, truncate | 7406 | // Not an even number of bytes, so we zext 1 byte, then bswap, shift right 1 byte, truncate |
| 7389 | ZigType *extended_type = get_int_type(g, int_type->data.integral.is_signed, | 7407 | ZigType *extended_type = get_int_type(g, int_type->data.integral.is_signed, |
| ... | @@ -7402,7 +7420,7 @@ static LLVMValueRef ir_render_bswap(CodeGen *g, Stage1Air *executable, Stage1Air | ... | @@ -7402,7 +7420,7 @@ static LLVMValueRef ir_render_bswap(CodeGen *g, Stage1Air *executable, Stage1Air |
| 7402 | LLVMValueRef extended = LLVMBuildZExt(g->builder, op, get_llvm_type(g, extended_type), ""); | 7420 | LLVMValueRef extended = LLVMBuildZExt(g->builder, op, get_llvm_type(g, extended_type), ""); |
| 7403 | // 00aabbcc | 7421 | // 00aabbcc |
| 7404 | LLVMValueRef fn_val = get_int_builtin_fn(g, extended_type, BuiltinFnIdBswap); | 7422 | LLVMValueRef fn_val = get_int_builtin_fn(g, extended_type, BuiltinFnIdBswap); |
| 7405 | LLVMValueRef swapped = LLVMBuildCall2(g->builder, LLVMTypeOf(fn_val), fn_val, &extended, 1, ""); | 7423 | LLVMValueRef swapped = LLVMBuildCall2(g->builder, LLVMGlobalGetValueType(fn_val), fn_val, &extended, 1, ""); |
| 7406 | // ccbbaa00 | 7424 | // ccbbaa00 |
| 7407 | LLVMValueRef shifted = ZigLLVMBuildLShrExact(g->builder, swapped, shift_amt, ""); | 7425 | LLVMValueRef shifted = ZigLLVMBuildLShrExact(g->builder, swapped, shift_amt, ""); |
| 7408 | // 00ccbbaa | 7426 | // 00ccbbaa |
| ... | @@ -7438,7 +7456,7 @@ static LLVMValueRef ir_render_bit_reverse(CodeGen *g, Stage1Air *executable, Sta | ... | @@ -7438,7 +7456,7 @@ static LLVMValueRef ir_render_bit_reverse(CodeGen *g, Stage1Air *executable, Sta |
| 7438 | ZigType *int_type = instruction->base.value->type; | 7456 | ZigType *int_type = instruction->base.value->type; |
| 7439 | assert(int_type->id == ZigTypeIdInt); | 7457 | assert(int_type->id == ZigTypeIdInt); |
| 7440 | LLVMValueRef fn_val = get_int_builtin_fn(g, instruction->base.value->type, BuiltinFnIdBitReverse); | 7458 | LLVMValueRef fn_val = get_int_builtin_fn(g, instruction->base.value->type, BuiltinFnIdBitReverse); |
| 7441 | return LLVMBuildCall2(g->builder, LLVMTypeOf(fn_val), fn_val, &op, 1, ""); | 7459 | return LLVMBuildCall2(g->builder, LLVMGlobalGetValueType(fn_val), fn_val, &op, 1, ""); |
| 7442 | } | 7460 | } |
| 7443 | | 7461 | |
| 7444 | static LLVMValueRef ir_render_vector_to_array(CodeGen *g, Stage1Air *executable, | 7462 | static LLVMValueRef ir_render_vector_to_array(CodeGen *g, Stage1Air *executable, |
| ... | @@ -7603,7 +7621,7 @@ static LLVMValueRef gen_await_early_return(CodeGen *g, Stage1AirInst *source_ins | ... | @@ -7603,7 +7621,7 @@ static LLVMValueRef gen_await_early_return(CodeGen *g, Stage1AirInst *source_ins |
| 7603 | bool is_llvm_alloca; | 7621 | bool is_llvm_alloca; |
| 7604 | LLVMValueRef dest_trace_ptr = get_cur_err_ret_trace_val(g, source_instr->scope, &is_llvm_alloca); | 7622 | LLVMValueRef dest_trace_ptr = get_cur_err_ret_trace_val(g, source_instr->scope, &is_llvm_alloca); |
| 7605 | LLVMValueRef args[] = { dest_trace_ptr, src_trace_ptr }; | 7623 | LLVMValueRef args[] = { dest_trace_ptr, src_trace_ptr }; |
| 7606 | ZigLLVMBuildCall(g->builder, LLVMTypeOf(get_merge_err_ret_traces_fn_val(g)), | 7624 | ZigLLVMBuildCall(g->builder, LLVMGlobalGetValueType(get_merge_err_ret_traces_fn_val(g)), |
| 7607 | get_merge_err_ret_traces_fn_val(g), args, 2, | 7625 | get_merge_err_ret_traces_fn_val(g), args, 2, |
| 7608 | get_llvm_cc(g, CallingConventionUnspecified), ZigLLVM_CallAttrAuto, ""); | 7626 | get_llvm_cc(g, CallingConventionUnspecified), ZigLLVM_CallAttrAuto, ""); |
| 7609 | } | 7627 | } |
| ... | @@ -9337,7 +9355,7 @@ static void do_code_gen(CodeGen *g) { | ... | @@ -9337,7 +9355,7 @@ static void do_code_gen(CodeGen *g) { |
| 9337 | LLVMValueRef zero = LLVMConstNull(usize->llvm_type); | 9355 | LLVMValueRef zero = LLVMConstNull(usize->llvm_type); |
| 9338 | LLVMValueRef indices[] = {zero, zero}; | 9356 | LLVMValueRef indices[] = {zero, zero}; |
| 9339 | LLVMValueRef err_ret_array_val_elem0_ptr = LLVMBuildInBoundsGEP2(g->builder, | 9357 | LLVMValueRef err_ret_array_val_elem0_ptr = LLVMBuildInBoundsGEP2(g->builder, |
| 9340 | usize_type_ref, err_ret_array_val, indices, 2, ""); | 9358 | LLVMGetAllocatedType(err_ret_array_val), err_ret_array_val, indices, 2, ""); |
| 9341 | ZigType *ptr_ptr_usize_type = get_pointer_to_type(g, get_pointer_to_type(g, usize, false), false); | 9359 | ZigType *ptr_ptr_usize_type = get_pointer_to_type(g, get_pointer_to_type(g, usize, false), false); |
| 9342 | gen_store(g, err_ret_array_val_elem0_ptr, ptr_field_ptr, ptr_ptr_usize_type); | 9360 | gen_store(g, err_ret_array_val_elem0_ptr, ptr_field_ptr, ptr_ptr_usize_type); |
| 9343 | | 9361 | |