| ... | @@ -745,7 +745,7 @@ pub const Object = struct { | ... | @@ -745,7 +745,7 @@ pub const Object = struct { |
| 745 | const param = llvm_func.getParam(llvm_arg_i); | 745 | const param = llvm_func.getParam(llvm_arg_i); |
| 746 | llvm_arg_i += 1; | 746 | llvm_arg_i += 1; |
| 747 | | 747 | |
| 748 | const param_llvm_ty = try dg.llvmType(param_ty); | 748 | const param_llvm_ty = try dg.lowerType(param_ty); |
| 749 | const abi_size = @intCast(c_uint, param_ty.abiSize(target)); | 749 | const abi_size = @intCast(c_uint, param_ty.abiSize(target)); |
| 750 | const int_llvm_ty = dg.context.intType(abi_size * 8); | 750 | const int_llvm_ty = dg.context.intType(abi_size * 8); |
| 751 | const int_ptr_llvm_ty = int_llvm_ty.pointerType(0); | 751 | const int_ptr_llvm_ty = int_llvm_ty.pointerType(0); |
| ... | @@ -775,7 +775,7 @@ pub const Object = struct { | ... | @@ -775,7 +775,7 @@ pub const Object = struct { |
| 775 | .Struct => { | 775 | .Struct => { |
| 776 | const fields = param_ty.structFields().values(); | 776 | const fields = param_ty.structFields().values(); |
| 777 | if (is_by_ref) { | 777 | if (is_by_ref) { |
| 778 | const param_llvm_ty = try dg.llvmType(param_ty); | 778 | const param_llvm_ty = try dg.lowerType(param_ty); |
| 779 | const arg_ptr = buildAllocaInner(builder, llvm_func, false, param_llvm_ty); | 779 | const arg_ptr = buildAllocaInner(builder, llvm_func, false, param_llvm_ty); |
| 780 | arg_ptr.setAlignment(param_ty.abiAlignment(target)); | 780 | arg_ptr.setAlignment(param_ty.abiAlignment(target)); |
| 781 | | 781 | |
| ... | @@ -2100,7 +2100,7 @@ pub const DeclGen = struct { | ... | @@ -2100,7 +2100,7 @@ pub const DeclGen = struct { |
| 2100 | break :init_val decl.val; | 2100 | break :init_val decl.val; |
| 2101 | }; | 2101 | }; |
| 2102 | if (init_val.tag() != .unreachable_value) { | 2102 | if (init_val.tag() != .unreachable_value) { |
| 2103 | const llvm_init = try dg.genTypedValue(.{ .ty = decl.ty, .val = init_val }); | 2103 | const llvm_init = try dg.lowerValue(.{ .ty = decl.ty, .val = init_val }); |
| 2104 | if (global.globalGetValueType() == llvm_init.typeOf()) { | 2104 | if (global.globalGetValueType() == llvm_init.typeOf()) { |
| 2105 | global.setInitializer(llvm_init); | 2105 | global.setInitializer(llvm_init); |
| 2106 | } else { | 2106 | } else { |
| ... | @@ -2171,7 +2171,7 @@ pub const DeclGen = struct { | ... | @@ -2171,7 +2171,7 @@ pub const DeclGen = struct { |
| 2171 | const target = dg.module.getTarget(); | 2171 | const target = dg.module.getTarget(); |
| 2172 | const sret = firstParamSRet(fn_info, target); | 2172 | const sret = firstParamSRet(fn_info, target); |
| 2173 | | 2173 | |
| 2174 | const fn_type = try dg.llvmType(zig_fn_type); | 2174 | const fn_type = try dg.lowerType(zig_fn_type); |
| 2175 | | 2175 | |
| 2176 | const fqn = try decl.getFullyQualifiedName(dg.module); | 2176 | const fqn = try decl.getFullyQualifiedName(dg.module); |
| 2177 | defer dg.gpa.free(fqn); | 2177 | defer dg.gpa.free(fqn); |
| ... | @@ -2198,7 +2198,7 @@ pub const DeclGen = struct { | ... | @@ -2198,7 +2198,7 @@ pub const DeclGen = struct { |
| 2198 | dg.addArgAttr(llvm_fn, 0, "nonnull"); // Sret pointers must not be address 0 | 2198 | dg.addArgAttr(llvm_fn, 0, "nonnull"); // Sret pointers must not be address 0 |
| 2199 | dg.addArgAttr(llvm_fn, 0, "noalias"); | 2199 | dg.addArgAttr(llvm_fn, 0, "noalias"); |
| 2200 | | 2200 | |
| 2201 | const raw_llvm_ret_ty = try dg.llvmType(fn_info.return_type); | 2201 | const raw_llvm_ret_ty = try dg.lowerType(fn_info.return_type); |
| 2202 | llvm_fn.addSretAttr(0, raw_llvm_ret_ty); | 2202 | llvm_fn.addSretAttr(0, raw_llvm_ret_ty); |
| 2203 | } | 2203 | } |
| 2204 | | 2204 | |
| ... | @@ -2291,7 +2291,7 @@ pub const DeclGen = struct { | ... | @@ -2291,7 +2291,7 @@ pub const DeclGen = struct { |
| 2291 | const fqn = try decl.getFullyQualifiedName(dg.module); | 2291 | const fqn = try decl.getFullyQualifiedName(dg.module); |
| 2292 | defer dg.gpa.free(fqn); | 2292 | defer dg.gpa.free(fqn); |
| 2293 | | 2293 | |
| 2294 | const llvm_type = try dg.llvmType(decl.ty); | 2294 | const llvm_type = try dg.lowerType(decl.ty); |
| 2295 | const llvm_addrspace = dg.llvmAddressSpace(decl.@"addrspace"); | 2295 | const llvm_addrspace = dg.llvmAddressSpace(decl.@"addrspace"); |
| 2296 | const llvm_global = dg.object.llvm_module.addGlobalInAddressSpace(llvm_type, fqn, llvm_addrspace); | 2296 | const llvm_global = dg.object.llvm_module.addGlobalInAddressSpace(llvm_type, fqn, llvm_addrspace); |
| 2297 | gop.value_ptr.* = llvm_global; | 2297 | gop.value_ptr.* = llvm_global; |
| ... | @@ -2345,15 +2345,15 @@ pub const DeclGen = struct { | ... | @@ -2345,15 +2345,15 @@ pub const DeclGen = struct { |
| 2345 | } | 2345 | } |
| 2346 | | 2346 | |
| 2347 | fn isUnnamedType(dg: *DeclGen, ty: Type, val: *const llvm.Value) bool { | 2347 | fn isUnnamedType(dg: *DeclGen, ty: Type, val: *const llvm.Value) bool { |
| 2348 | // Once `llvmType` succeeds, successive calls to it with the same Zig type | 2348 | // Once `lowerType` succeeds, successive calls to it with the same Zig type |
| 2349 | // are guaranteed to succeed. So if a call to `llvmType` fails here it means | 2349 | // are guaranteed to succeed. So if a call to `lowerType` fails here it means |
| 2350 | // it is the first time lowering the type, which means the value can't possible | 2350 | // it is the first time lowering the type, which means the value can't possible |
| 2351 | // have that type. | 2351 | // have that type. |
| 2352 | const llvm_ty = dg.llvmType(ty) catch return true; | 2352 | const llvm_ty = dg.lowerType(ty) catch return true; |
| 2353 | return val.typeOf() != llvm_ty; | 2353 | return val.typeOf() != llvm_ty; |
| 2354 | } | 2354 | } |
| 2355 | | 2355 | |
| 2356 | fn llvmType(dg: *DeclGen, t: Type) Allocator.Error!*const llvm.Type { | 2356 | fn lowerType(dg: *DeclGen, t: Type) Allocator.Error!*const llvm.Type { |
| 2357 | const gpa = dg.gpa; | 2357 | const gpa = dg.gpa; |
| 2358 | const target = dg.module.getTarget(); | 2358 | const target = dg.module.getTarget(); |
| 2359 | switch (t.zigTypeTag()) { | 2359 | switch (t.zigTypeTag()) { |
| ... | @@ -2385,8 +2385,8 @@ pub const DeclGen = struct { | ... | @@ -2385,8 +2385,8 @@ pub const DeclGen = struct { |
| 2385 | const ptr_type = t.slicePtrFieldType(&buf); | 2385 | const ptr_type = t.slicePtrFieldType(&buf); |
| 2386 | | 2386 | |
| 2387 | const fields: [2]*const llvm.Type = .{ | 2387 | const fields: [2]*const llvm.Type = .{ |
| 2388 | try dg.llvmType(ptr_type), | 2388 | try dg.lowerType(ptr_type), |
| 2389 | try dg.llvmType(Type.usize), | 2389 | try dg.lowerType(Type.usize), |
| 2390 | }; | 2390 | }; |
| 2391 | return dg.context.structType(&fields, fields.len, .False); | 2391 | return dg.context.structType(&fields, fields.len, .False); |
| 2392 | } | 2392 | } |
| ... | @@ -2402,7 +2402,7 @@ pub const DeclGen = struct { | ... | @@ -2402,7 +2402,7 @@ pub const DeclGen = struct { |
| 2402 | else => elem_ty.hasRuntimeBitsIgnoreComptime(), | 2402 | else => elem_ty.hasRuntimeBitsIgnoreComptime(), |
| 2403 | }; | 2403 | }; |
| 2404 | const llvm_elem_ty = if (lower_elem_ty) | 2404 | const llvm_elem_ty = if (lower_elem_ty) |
| 2405 | try dg.llvmType(elem_ty) | 2405 | try dg.lowerType(elem_ty) |
| 2406 | else | 2406 | else |
| 2407 | dg.context.intType(8); | 2407 | dg.context.intType(8); |
| 2408 | return llvm_elem_ty.pointerType(llvm_addrspace); | 2408 | return llvm_elem_ty.pointerType(llvm_addrspace); |
| ... | @@ -2430,12 +2430,12 @@ pub const DeclGen = struct { | ... | @@ -2430,12 +2430,12 @@ pub const DeclGen = struct { |
| 2430 | .Array => { | 2430 | .Array => { |
| 2431 | const elem_ty = t.childType(); | 2431 | const elem_ty = t.childType(); |
| 2432 | assert(elem_ty.onePossibleValue() == null); | 2432 | assert(elem_ty.onePossibleValue() == null); |
| 2433 | const elem_llvm_ty = try dg.llvmType(elem_ty); | 2433 | const elem_llvm_ty = try dg.lowerType(elem_ty); |
| 2434 | const total_len = t.arrayLen() + @boolToInt(t.sentinel() != null); | 2434 | const total_len = t.arrayLen() + @boolToInt(t.sentinel() != null); |
| 2435 | return elem_llvm_ty.arrayType(@intCast(c_uint, total_len)); | 2435 | return elem_llvm_ty.arrayType(@intCast(c_uint, total_len)); |
| 2436 | }, | 2436 | }, |
| 2437 | .Vector => { | 2437 | .Vector => { |
| 2438 | const elem_type = try dg.llvmType(t.childType()); | 2438 | const elem_type = try dg.lowerType(t.childType()); |
| 2439 | return elem_type.vectorType(t.vectorLen()); | 2439 | return elem_type.vectorType(t.vectorLen()); |
| 2440 | }, | 2440 | }, |
| 2441 | .Optional => { | 2441 | .Optional => { |
| ... | @@ -2444,7 +2444,7 @@ pub const DeclGen = struct { | ... | @@ -2444,7 +2444,7 @@ pub const DeclGen = struct { |
| 2444 | if (!child_ty.hasRuntimeBitsIgnoreComptime()) { | 2444 | if (!child_ty.hasRuntimeBitsIgnoreComptime()) { |
| 2445 | return dg.context.intType(1); | 2445 | return dg.context.intType(1); |
| 2446 | } | 2446 | } |
| 2447 | const payload_llvm_ty = try dg.llvmType(child_ty); | 2447 | const payload_llvm_ty = try dg.lowerType(child_ty); |
| 2448 | if (t.optionalReprIsPayload()) { | 2448 | if (t.optionalReprIsPayload()) { |
| 2449 | return payload_llvm_ty; | 2449 | return payload_llvm_ty; |
| 2450 | } | 2450 | } |
| ... | @@ -2458,13 +2458,13 @@ pub const DeclGen = struct { | ... | @@ -2458,13 +2458,13 @@ pub const DeclGen = struct { |
| 2458 | const error_type = t.errorUnionSet(); | 2458 | const error_type = t.errorUnionSet(); |
| 2459 | const payload_type = t.errorUnionPayload(); | 2459 | const payload_type = t.errorUnionPayload(); |
| 2460 | if (error_type.errorSetCardinality() == .zero) { | 2460 | if (error_type.errorSetCardinality() == .zero) { |
| 2461 | return dg.llvmType(payload_type); | 2461 | return dg.lowerType(payload_type); |
| 2462 | } | 2462 | } |
| 2463 | if (!payload_type.hasRuntimeBitsIgnoreComptime()) { | 2463 | if (!payload_type.hasRuntimeBitsIgnoreComptime()) { |
| 2464 | return try dg.llvmType(Type.anyerror); | 2464 | return try dg.lowerType(Type.anyerror); |
| 2465 | } | 2465 | } |
| 2466 | const llvm_error_type = try dg.llvmType(error_type); | 2466 | const llvm_error_type = try dg.lowerType(error_type); |
| 2467 | const llvm_payload_type = try dg.llvmType(payload_type); | 2467 | const llvm_payload_type = try dg.lowerType(payload_type); |
| 2468 | | 2468 | |
| 2469 | const payload_align = payload_type.abiAlignment(target); | 2469 | const payload_align = payload_type.abiAlignment(target); |
| 2470 | const error_align = Type.anyerror.abiAlignment(target); | 2470 | const error_align = Type.anyerror.abiAlignment(target); |
| ... | @@ -2515,7 +2515,7 @@ pub const DeclGen = struct { | ... | @@ -2515,7 +2515,7 @@ pub const DeclGen = struct { |
| 2515 | const llvm_array_ty = dg.context.intType(8).arrayType(@intCast(c_uint, padding_len)); | 2515 | const llvm_array_ty = dg.context.intType(8).arrayType(@intCast(c_uint, padding_len)); |
| 2516 | try llvm_field_types.append(gpa, llvm_array_ty); | 2516 | try llvm_field_types.append(gpa, llvm_array_ty); |
| 2517 | } | 2517 | } |
| 2518 | const field_llvm_ty = try dg.llvmType(field_ty); | 2518 | const field_llvm_ty = try dg.lowerType(field_ty); |
| 2519 | try llvm_field_types.append(gpa, field_llvm_ty); | 2519 | try llvm_field_types.append(gpa, field_llvm_ty); |
| 2520 | | 2520 | |
| 2521 | offset += field_ty.abiSize(target); | 2521 | offset += field_ty.abiSize(target); |
| ... | @@ -2544,7 +2544,7 @@ pub const DeclGen = struct { | ... | @@ -2544,7 +2544,7 @@ pub const DeclGen = struct { |
| 2544 | if (struct_obj.layout == .Packed) { | 2544 | if (struct_obj.layout == .Packed) { |
| 2545 | var buf: Type.Payload.Bits = undefined; | 2545 | var buf: Type.Payload.Bits = undefined; |
| 2546 | const int_ty = struct_obj.packedIntegerType(target, &buf); | 2546 | const int_ty = struct_obj.packedIntegerType(target, &buf); |
| 2547 | const int_llvm_ty = try dg.llvmType(int_ty); | 2547 | const int_llvm_ty = try dg.lowerType(int_ty); |
| 2548 | gop.value_ptr.* = int_llvm_ty; | 2548 | gop.value_ptr.* = int_llvm_ty; |
| 2549 | return int_llvm_ty; | 2549 | return int_llvm_ty; |
| 2550 | } | 2550 | } |
| ... | @@ -2579,7 +2579,7 @@ pub const DeclGen = struct { | ... | @@ -2579,7 +2579,7 @@ pub const DeclGen = struct { |
| 2579 | const llvm_array_ty = dg.context.intType(8).arrayType(@intCast(c_uint, padding_len)); | 2579 | const llvm_array_ty = dg.context.intType(8).arrayType(@intCast(c_uint, padding_len)); |
| 2580 | try llvm_field_types.append(gpa, llvm_array_ty); | 2580 | try llvm_field_types.append(gpa, llvm_array_ty); |
| 2581 | } | 2581 | } |
| 2582 | const field_llvm_ty = try dg.llvmType(field.ty); | 2582 | const field_llvm_ty = try dg.lowerType(field.ty); |
| 2583 | try llvm_field_types.append(gpa, field_llvm_ty); | 2583 | try llvm_field_types.append(gpa, field_llvm_ty); |
| 2584 | | 2584 | |
| 2585 | offset += field.ty.abiSize(target); | 2585 | offset += field.ty.abiSize(target); |
| ... | @@ -2614,7 +2614,7 @@ pub const DeclGen = struct { | ... | @@ -2614,7 +2614,7 @@ pub const DeclGen = struct { |
| 2614 | const union_obj = t.cast(Type.Payload.Union).?.data; | 2614 | const union_obj = t.cast(Type.Payload.Union).?.data; |
| 2615 | | 2615 | |
| 2616 | if (layout.payload_size == 0) { | 2616 | if (layout.payload_size == 0) { |
| 2617 | const enum_tag_llvm_ty = try dg.llvmType(union_obj.tag_ty); | 2617 | const enum_tag_llvm_ty = try dg.lowerType(union_obj.tag_ty); |
| 2618 | gop.value_ptr.* = enum_tag_llvm_ty; | 2618 | gop.value_ptr.* = enum_tag_llvm_ty; |
| 2619 | return enum_tag_llvm_ty; | 2619 | return enum_tag_llvm_ty; |
| 2620 | } | 2620 | } |
| ... | @@ -2626,7 +2626,7 @@ pub const DeclGen = struct { | ... | @@ -2626,7 +2626,7 @@ pub const DeclGen = struct { |
| 2626 | gop.value_ptr.* = llvm_union_ty; // must be done before any recursive calls | 2626 | gop.value_ptr.* = llvm_union_ty; // must be done before any recursive calls |
| 2627 | | 2627 | |
| 2628 | const aligned_field = union_obj.fields.values()[layout.most_aligned_field]; | 2628 | const aligned_field = union_obj.fields.values()[layout.most_aligned_field]; |
| 2629 | const llvm_aligned_field_ty = try dg.llvmType(aligned_field.ty); | 2629 | const llvm_aligned_field_ty = try dg.lowerType(aligned_field.ty); |
| 2630 | | 2630 | |
| 2631 | const llvm_payload_ty = t: { | 2631 | const llvm_payload_ty = t: { |
| 2632 | if (layout.most_aligned_field_size == layout.payload_size) { | 2632 | if (layout.most_aligned_field_size == layout.payload_size) { |
| ... | @@ -2645,7 +2645,7 @@ pub const DeclGen = struct { | ... | @@ -2645,7 +2645,7 @@ pub const DeclGen = struct { |
| 2645 | llvm_union_ty.structSetBody(&llvm_fields, llvm_fields.len, .False); | 2645 | llvm_union_ty.structSetBody(&llvm_fields, llvm_fields.len, .False); |
| 2646 | return llvm_union_ty; | 2646 | return llvm_union_ty; |
| 2647 | } | 2647 | } |
| 2648 | const enum_tag_llvm_ty = try dg.llvmType(union_obj.tag_ty); | 2648 | const enum_tag_llvm_ty = try dg.lowerType(union_obj.tag_ty); |
| 2649 | | 2649 | |
| 2650 | // Put the tag before or after the payload depending on which one's | 2650 | // Put the tag before or after the payload depending on which one's |
| 2651 | // alignment is greater. | 2651 | // alignment is greater. |
| ... | @@ -2667,7 +2667,7 @@ pub const DeclGen = struct { | ... | @@ -2667,7 +2667,7 @@ pub const DeclGen = struct { |
| 2667 | llvm_union_ty.structSetBody(&llvm_fields, llvm_fields_len, .False); | 2667 | llvm_union_ty.structSetBody(&llvm_fields, llvm_fields_len, .False); |
| 2668 | return llvm_union_ty; | 2668 | return llvm_union_ty; |
| 2669 | }, | 2669 | }, |
| 2670 | .Fn => return llvmTypeFn(dg, t), | 2670 | .Fn => return lowerTypeFn(dg, t), |
| 2671 | .ComptimeInt => unreachable, | 2671 | .ComptimeInt => unreachable, |
| 2672 | .ComptimeFloat => unreachable, | 2672 | .ComptimeFloat => unreachable, |
| 2673 | .Type => unreachable, | 2673 | .Type => unreachable, |
| ... | @@ -2682,7 +2682,7 @@ pub const DeclGen = struct { | ... | @@ -2682,7 +2682,7 @@ pub const DeclGen = struct { |
| 2682 | } | 2682 | } |
| 2683 | } | 2683 | } |
| 2684 | | 2684 | |
| 2685 | fn llvmTypeFn(dg: *DeclGen, fn_ty: Type) Allocator.Error!*const llvm.Type { | 2685 | fn lowerTypeFn(dg: *DeclGen, fn_ty: Type) Allocator.Error!*const llvm.Type { |
| 2686 | const target = dg.module.getTarget(); | 2686 | const target = dg.module.getTarget(); |
| 2687 | const fn_info = fn_ty.fnInfo(); | 2687 | const fn_info = fn_ty.fnInfo(); |
| 2688 | const llvm_ret_ty = try lowerFnRetTy(dg, fn_info); | 2688 | const llvm_ret_ty = try lowerFnRetTy(dg, fn_info); |
| ... | @@ -2691,7 +2691,7 @@ pub const DeclGen = struct { | ... | @@ -2691,7 +2691,7 @@ pub const DeclGen = struct { |
| 2691 | defer llvm_params.deinit(); | 2691 | defer llvm_params.deinit(); |
| 2692 | | 2692 | |
| 2693 | if (firstParamSRet(fn_info, target)) { | 2693 | if (firstParamSRet(fn_info, target)) { |
| 2694 | const llvm_sret_ty = try dg.llvmType(fn_info.return_type); | 2694 | const llvm_sret_ty = try dg.lowerType(fn_info.return_type); |
| 2695 | try llvm_params.append(llvm_sret_ty.pointerType(0)); | 2695 | try llvm_params.append(llvm_sret_ty.pointerType(0)); |
| 2696 | } | 2696 | } |
| 2697 | | 2697 | |
| ... | @@ -2703,7 +2703,7 @@ pub const DeclGen = struct { | ... | @@ -2703,7 +2703,7 @@ pub const DeclGen = struct { |
| 2703 | .data = dg.object.getStackTraceType(), | 2703 | .data = dg.object.getStackTraceType(), |
| 2704 | }; | 2704 | }; |
| 2705 | const ptr_ty = Type.initPayload(&ptr_ty_payload.base); | 2705 | const ptr_ty = Type.initPayload(&ptr_ty_payload.base); |
| 2706 | try llvm_params.append(try dg.llvmType(ptr_ty)); | 2706 | try llvm_params.append(try dg.lowerType(ptr_ty)); |
| 2707 | } | 2707 | } |
| 2708 | | 2708 | |
| 2709 | var it = iterateParamTypes(dg, fn_info); | 2709 | var it = iterateParamTypes(dg, fn_info); |
| ... | @@ -2711,11 +2711,11 @@ pub const DeclGen = struct { | ... | @@ -2711,11 +2711,11 @@ pub const DeclGen = struct { |
| 2711 | .no_bits => continue, | 2711 | .no_bits => continue, |
| 2712 | .byval => { | 2712 | .byval => { |
| 2713 | const param_ty = fn_info.param_types[it.zig_index - 1]; | 2713 | const param_ty = fn_info.param_types[it.zig_index - 1]; |
| 2714 | try llvm_params.append(try dg.llvmType(param_ty)); | 2714 | try llvm_params.append(try dg.lowerType(param_ty)); |
| 2715 | }, | 2715 | }, |
| 2716 | .byref => { | 2716 | .byref => { |
| 2717 | const param_ty = fn_info.param_types[it.zig_index - 1]; | 2717 | const param_ty = fn_info.param_types[it.zig_index - 1]; |
| 2718 | const raw_llvm_ty = try dg.llvmType(param_ty); | 2718 | const raw_llvm_ty = try dg.lowerType(param_ty); |
| 2719 | try llvm_params.append(raw_llvm_ty.pointerType(0)); | 2719 | try llvm_params.append(raw_llvm_ty.pointerType(0)); |
| 2720 | }, | 2720 | }, |
| 2721 | .abi_sized_int => { | 2721 | .abi_sized_int => { |
| ... | @@ -2757,7 +2757,7 @@ pub const DeclGen = struct { | ... | @@ -2757,7 +2757,7 @@ pub const DeclGen = struct { |
| 2757 | // one field; in this case keep the type information | 2757 | // one field; in this case keep the type information |
| 2758 | // to avoid the potentially costly ptrtoint/bitcast. | 2758 | // to avoid the potentially costly ptrtoint/bitcast. |
| 2759 | if (bits_used == 0 and field_abi_bits == int_bits) { | 2759 | if (bits_used == 0 and field_abi_bits == int_bits) { |
| 2760 | const llvm_field_ty = try dg.llvmType(field.ty); | 2760 | const llvm_field_ty = try dg.lowerType(field.ty); |
| 2761 | llvm_params.appendAssumeCapacity(llvm_field_ty); | 2761 | llvm_params.appendAssumeCapacity(llvm_field_ty); |
| 2762 | field_i += 1; | 2762 | field_i += 1; |
| 2763 | if (field_i >= fields.len) { | 2763 | if (field_i >= fields.len) { |
| ... | @@ -2795,16 +2795,16 @@ pub const DeclGen = struct { | ... | @@ -2795,16 +2795,16 @@ pub const DeclGen = struct { |
| 2795 | ); | 2795 | ); |
| 2796 | } | 2796 | } |
| 2797 | | 2797 | |
| 2798 | fn genTypedValue(dg: *DeclGen, tv: TypedValue) Error!*const llvm.Value { | 2798 | fn lowerValue(dg: *DeclGen, tv: TypedValue) Error!*const llvm.Value { |
| 2799 | if (tv.val.isUndef()) { | 2799 | if (tv.val.isUndef()) { |
| 2800 | const llvm_type = try dg.llvmType(tv.ty); | 2800 | const llvm_type = try dg.lowerType(tv.ty); |
| 2801 | return llvm_type.getUndef(); | 2801 | return llvm_type.getUndef(); |
| 2802 | } | 2802 | } |
| 2803 | const target = dg.module.getTarget(); | 2803 | const target = dg.module.getTarget(); |
| 2804 | | 2804 | |
| 2805 | switch (tv.ty.zigTypeTag()) { | 2805 | switch (tv.ty.zigTypeTag()) { |
| 2806 | .Bool => { | 2806 | .Bool => { |
| 2807 | const llvm_type = try dg.llvmType(tv.ty); | 2807 | const llvm_type = try dg.lowerType(tv.ty); |
| 2808 | return if (tv.val.toBool()) llvm_type.constAllOnes() else llvm_type.constNull(); | 2808 | return if (tv.val.toBool()) llvm_type.constAllOnes() else llvm_type.constNull(); |
| 2809 | }, | 2809 | }, |
| 2810 | // TODO this duplicates code with Pointer but they should share the handling | 2810 | // TODO this duplicates code with Pointer but they should share the handling |
| ... | @@ -2865,7 +2865,7 @@ pub const DeclGen = struct { | ... | @@ -2865,7 +2865,7 @@ pub const DeclGen = struct { |
| 2865 | return unsigned_val; | 2865 | return unsigned_val; |
| 2866 | }, | 2866 | }, |
| 2867 | .Float => { | 2867 | .Float => { |
| 2868 | const llvm_ty = try dg.llvmType(tv.ty); | 2868 | const llvm_ty = try dg.lowerType(tv.ty); |
| 2869 | switch (tv.ty.floatBits(target)) { | 2869 | switch (tv.ty.floatBits(target)) { |
| 2870 | 16, 32, 64 => return llvm_ty.constReal(tv.val.toFloat(f64)), | 2870 | 16, 32, 64 => return llvm_ty.constReal(tv.val.toFloat(f64)), |
| 2871 | 80 => { | 2871 | 80 => { |
| ... | @@ -2902,7 +2902,7 @@ pub const DeclGen = struct { | ... | @@ -2902,7 +2902,7 @@ pub const DeclGen = struct { |
| 2902 | const decl = dg.module.declPtr(decl_index); | 2902 | const decl = dg.module.declPtr(decl_index); |
| 2903 | dg.module.markDeclAlive(decl); | 2903 | dg.module.markDeclAlive(decl); |
| 2904 | const val = try dg.resolveGlobalDecl(decl_index); | 2904 | const val = try dg.resolveGlobalDecl(decl_index); |
| 2905 | const llvm_var_type = try dg.llvmType(tv.ty); | 2905 | const llvm_var_type = try dg.lowerType(tv.ty); |
| 2906 | const llvm_addrspace = dg.llvmAddressSpace(decl.@"addrspace"); | 2906 | const llvm_addrspace = dg.llvmAddressSpace(decl.@"addrspace"); |
| 2907 | const llvm_type = llvm_var_type.pointerType(llvm_addrspace); | 2907 | const llvm_type = llvm_var_type.pointerType(llvm_addrspace); |
| 2908 | return val.constBitCast(llvm_type); | 2908 | return val.constBitCast(llvm_type); |
| ... | @@ -2911,11 +2911,11 @@ pub const DeclGen = struct { | ... | @@ -2911,11 +2911,11 @@ pub const DeclGen = struct { |
| 2911 | const slice = tv.val.castTag(.slice).?.data; | 2911 | const slice = tv.val.castTag(.slice).?.data; |
| 2912 | var buf: Type.SlicePtrFieldTypeBuffer = undefined; | 2912 | var buf: Type.SlicePtrFieldTypeBuffer = undefined; |
| 2913 | const fields: [2]*const llvm.Value = .{ | 2913 | const fields: [2]*const llvm.Value = .{ |
| 2914 | try dg.genTypedValue(.{ | 2914 | try dg.lowerValue(.{ |
| 2915 | .ty = tv.ty.slicePtrFieldType(&buf), | 2915 | .ty = tv.ty.slicePtrFieldType(&buf), |
| 2916 | .val = slice.ptr, | 2916 | .val = slice.ptr, |
| 2917 | }), | 2917 | }), |
| 2918 | try dg.genTypedValue(.{ | 2918 | try dg.lowerValue(.{ |
| 2919 | .ty = Type.usize, | 2919 | .ty = Type.usize, |
| 2920 | .val = slice.len, | 2920 | .val = slice.len, |
| 2921 | }), | 2921 | }), |
| ... | @@ -2923,15 +2923,15 @@ pub const DeclGen = struct { | ... | @@ -2923,15 +2923,15 @@ pub const DeclGen = struct { |
| 2923 | return dg.context.constStruct(&fields, fields.len, .False); | 2923 | return dg.context.constStruct(&fields, fields.len, .False); |
| 2924 | }, | 2924 | }, |
| 2925 | .int_u64, .one, .int_big_positive => { | 2925 | .int_u64, .one, .int_big_positive => { |
| 2926 | const llvm_usize = try dg.llvmType(Type.usize); | 2926 | const llvm_usize = try dg.lowerType(Type.usize); |
| 2927 | const llvm_int = llvm_usize.constInt(tv.val.toUnsignedInt(target), .False); | 2927 | const llvm_int = llvm_usize.constInt(tv.val.toUnsignedInt(target), .False); |
| 2928 | return llvm_int.constIntToPtr(try dg.llvmType(tv.ty)); | 2928 | return llvm_int.constIntToPtr(try dg.lowerType(tv.ty)); |
| 2929 | }, | 2929 | }, |
| 2930 | .field_ptr, .opt_payload_ptr, .eu_payload_ptr, .elem_ptr => { | 2930 | .field_ptr, .opt_payload_ptr, .eu_payload_ptr, .elem_ptr => { |
| 2931 | return dg.lowerParentPtr(tv.val, tv.ty.childType()); | 2931 | return dg.lowerParentPtr(tv.val, tv.ty.childType()); |
| 2932 | }, | 2932 | }, |
| 2933 | .null_value, .zero => { | 2933 | .null_value, .zero => { |
| 2934 | const llvm_type = try dg.llvmType(tv.ty); | 2934 | const llvm_type = try dg.lowerType(tv.ty); |
| 2935 | return llvm_type.constNull(); | 2935 | return llvm_type.constNull(); |
| 2936 | }, | 2936 | }, |
| 2937 | else => |tag| return dg.todo("implement const of pointer type '{}' ({})", .{ | 2937 | else => |tag| return dg.todo("implement const of pointer type '{}' ({})", .{ |
| ... | @@ -2986,7 +2986,7 @@ pub const DeclGen = struct { | ... | @@ -2986,7 +2986,7 @@ pub const DeclGen = struct { |
| 2986 | defer gpa.free(llvm_elems); | 2986 | defer gpa.free(llvm_elems); |
| 2987 | var need_unnamed = false; | 2987 | var need_unnamed = false; |
| 2988 | for (elem_vals[0..len]) |elem_val, i| { | 2988 | for (elem_vals[0..len]) |elem_val, i| { |
| 2989 | llvm_elems[i] = try dg.genTypedValue(.{ .ty = elem_ty, .val = elem_val }); | 2989 | llvm_elems[i] = try dg.lowerValue(.{ .ty = elem_ty, .val = elem_val }); |
| 2990 | need_unnamed = need_unnamed or dg.isUnnamedType(elem_ty, llvm_elems[i]); | 2990 | need_unnamed = need_unnamed or dg.isUnnamedType(elem_ty, llvm_elems[i]); |
| 2991 | } | 2991 | } |
| 2992 | if (need_unnamed) { | 2992 | if (need_unnamed) { |
| ... | @@ -2996,7 +2996,7 @@ pub const DeclGen = struct { | ... | @@ -2996,7 +2996,7 @@ pub const DeclGen = struct { |
| 2996 | .True, | 2996 | .True, |
| 2997 | ); | 2997 | ); |
| 2998 | } else { | 2998 | } else { |
| 2999 | const llvm_elem_ty = try dg.llvmType(elem_ty); | 2999 | const llvm_elem_ty = try dg.lowerType(elem_ty); |
| 3000 | return llvm_elem_ty.constArray( | 3000 | return llvm_elem_ty.constArray( |
| 3001 | llvm_elems.ptr, | 3001 | llvm_elems.ptr, |
| 3002 | @intCast(c_uint, llvm_elems.len), | 3002 | @intCast(c_uint, llvm_elems.len), |
| ... | @@ -3016,13 +3016,13 @@ pub const DeclGen = struct { | ... | @@ -3016,13 +3016,13 @@ pub const DeclGen = struct { |
| 3016 | var need_unnamed = false; | 3016 | var need_unnamed = false; |
| 3017 | if (len != 0) { | 3017 | if (len != 0) { |
| 3018 | for (llvm_elems[0..len]) |*elem| { | 3018 | for (llvm_elems[0..len]) |*elem| { |
| 3019 | elem.* = try dg.genTypedValue(.{ .ty = elem_ty, .val = val }); | 3019 | elem.* = try dg.lowerValue(.{ .ty = elem_ty, .val = val }); |
| 3020 | } | 3020 | } |
| 3021 | need_unnamed = need_unnamed or dg.isUnnamedType(elem_ty, llvm_elems[0]); | 3021 | need_unnamed = need_unnamed or dg.isUnnamedType(elem_ty, llvm_elems[0]); |
| 3022 | } | 3022 | } |
| 3023 | | 3023 | |
| 3024 | if (sentinel) |sent| { | 3024 | if (sentinel) |sent| { |
| 3025 | llvm_elems[len] = try dg.genTypedValue(.{ .ty = elem_ty, .val = sent }); | 3025 | llvm_elems[len] = try dg.lowerValue(.{ .ty = elem_ty, .val = sent }); |
| 3026 | need_unnamed = need_unnamed or dg.isUnnamedType(elem_ty, llvm_elems[len]); | 3026 | need_unnamed = need_unnamed or dg.isUnnamedType(elem_ty, llvm_elems[len]); |
| 3027 | } | 3027 | } |
| 3028 | | 3028 | |
| ... | @@ -3033,7 +3033,7 @@ pub const DeclGen = struct { | ... | @@ -3033,7 +3033,7 @@ pub const DeclGen = struct { |
| 3033 | .True, | 3033 | .True, |
| 3034 | ); | 3034 | ); |
| 3035 | } else { | 3035 | } else { |
| 3036 | const llvm_elem_ty = try dg.llvmType(elem_ty); | 3036 | const llvm_elem_ty = try dg.lowerType(elem_ty); |
| 3037 | return llvm_elem_ty.constArray( | 3037 | return llvm_elem_ty.constArray( |
| 3038 | llvm_elems.ptr, | 3038 | llvm_elems.ptr, |
| 3039 | @intCast(c_uint, llvm_elems.len), | 3039 | @intCast(c_uint, llvm_elems.len), |
| ... | @@ -3043,13 +3043,13 @@ pub const DeclGen = struct { | ... | @@ -3043,13 +3043,13 @@ pub const DeclGen = struct { |
| 3043 | .empty_array_sentinel => { | 3043 | .empty_array_sentinel => { |
| 3044 | const elem_ty = tv.ty.elemType(); | 3044 | const elem_ty = tv.ty.elemType(); |
| 3045 | const sent_val = tv.ty.sentinel().?; | 3045 | const sent_val = tv.ty.sentinel().?; |
| 3046 | const sentinel = try dg.genTypedValue(.{ .ty = elem_ty, .val = sent_val }); | 3046 | const sentinel = try dg.lowerValue(.{ .ty = elem_ty, .val = sent_val }); |
| 3047 | const llvm_elems: [1]*const llvm.Value = .{sentinel}; | 3047 | const llvm_elems: [1]*const llvm.Value = .{sentinel}; |
| 3048 | const need_unnamed = dg.isUnnamedType(elem_ty, llvm_elems[0]); | 3048 | const need_unnamed = dg.isUnnamedType(elem_ty, llvm_elems[0]); |
| 3049 | if (need_unnamed) { | 3049 | if (need_unnamed) { |
| 3050 | return dg.context.constStruct(&llvm_elems, llvm_elems.len, .True); | 3050 | return dg.context.constStruct(&llvm_elems, llvm_elems.len, .True); |
| 3051 | } else { | 3051 | } else { |
| 3052 | const llvm_elem_ty = try dg.llvmType(elem_ty); | 3052 | const llvm_elem_ty = try dg.lowerType(elem_ty); |
| 3053 | return llvm_elem_ty.constArray(&llvm_elems, llvm_elems.len); | 3053 | return llvm_elem_ty.constArray(&llvm_elems, llvm_elems.len); |
| 3054 | } | 3054 | } |
| 3055 | }, | 3055 | }, |
| ... | @@ -3066,17 +3066,17 @@ pub const DeclGen = struct { | ... | @@ -3066,17 +3066,17 @@ pub const DeclGen = struct { |
| 3066 | } | 3066 | } |
| 3067 | if (tv.ty.optionalReprIsPayload()) { | 3067 | if (tv.ty.optionalReprIsPayload()) { |
| 3068 | if (tv.val.castTag(.opt_payload)) |payload| { | 3068 | if (tv.val.castTag(.opt_payload)) |payload| { |
| 3069 | return dg.genTypedValue(.{ .ty = payload_ty, .val = payload.data }); | 3069 | return dg.lowerValue(.{ .ty = payload_ty, .val = payload.data }); |
| 3070 | } else if (is_pl) { | 3070 | } else if (is_pl) { |
| 3071 | return dg.genTypedValue(.{ .ty = payload_ty, .val = tv.val }); | 3071 | return dg.lowerValue(.{ .ty = payload_ty, .val = tv.val }); |
| 3072 | } else { | 3072 | } else { |
| 3073 | const llvm_ty = try dg.llvmType(tv.ty); | 3073 | const llvm_ty = try dg.lowerType(tv.ty); |
| 3074 | return llvm_ty.constNull(); | 3074 | return llvm_ty.constNull(); |
| 3075 | } | 3075 | } |
| 3076 | } | 3076 | } |
| 3077 | assert(payload_ty.zigTypeTag() != .Fn); | 3077 | assert(payload_ty.zigTypeTag() != .Fn); |
| 3078 | const fields: [2]*const llvm.Value = .{ | 3078 | const fields: [2]*const llvm.Value = .{ |
| 3079 | try dg.genTypedValue(.{ | 3079 | try dg.lowerValue(.{ |
| 3080 | .ty = payload_ty, | 3080 | .ty = payload_ty, |
| 3081 | .val = if (tv.val.castTag(.opt_payload)) |pl| pl.data else Value.initTag(.undef), | 3081 | .val = if (tv.val.castTag(.opt_payload)) |pl| pl.data else Value.initTag(.undef), |
| 3082 | }), | 3082 | }), |
| ... | @@ -3095,7 +3095,7 @@ pub const DeclGen = struct { | ... | @@ -3095,7 +3095,7 @@ pub const DeclGen = struct { |
| 3095 | return dg.resolveLlvmFunction(fn_decl_index); | 3095 | return dg.resolveLlvmFunction(fn_decl_index); |
| 3096 | }, | 3096 | }, |
| 3097 | .ErrorSet => { | 3097 | .ErrorSet => { |
| 3098 | const llvm_ty = try dg.llvmType(tv.ty); | 3098 | const llvm_ty = try dg.lowerType(tv.ty); |
| 3099 | switch (tv.val.tag()) { | 3099 | switch (tv.val.tag()) { |
| 3100 | .@"error" => { | 3100 | .@"error" => { |
| 3101 | const err_name = tv.val.castTag(.@"error").?.data.name; | 3101 | const err_name = tv.val.castTag(.@"error").?.data.name; |
| ... | @@ -3113,23 +3113,23 @@ pub const DeclGen = struct { | ... | @@ -3113,23 +3113,23 @@ pub const DeclGen = struct { |
| 3113 | const payload_type = tv.ty.errorUnionPayload(); | 3113 | const payload_type = tv.ty.errorUnionPayload(); |
| 3114 | if (error_type.errorSetCardinality() == .zero) { | 3114 | if (error_type.errorSetCardinality() == .zero) { |
| 3115 | const payload_val = tv.val.castTag(.eu_payload).?.data; | 3115 | const payload_val = tv.val.castTag(.eu_payload).?.data; |
| 3116 | return dg.genTypedValue(.{ .ty = payload_type, .val = payload_val }); | 3116 | return dg.lowerValue(.{ .ty = payload_type, .val = payload_val }); |
| 3117 | } | 3117 | } |
| 3118 | const is_pl = tv.val.errorUnionIsPayload(); | 3118 | const is_pl = tv.val.errorUnionIsPayload(); |
| 3119 | | 3119 | |
| 3120 | if (!payload_type.hasRuntimeBitsIgnoreComptime()) { | 3120 | if (!payload_type.hasRuntimeBitsIgnoreComptime()) { |
| 3121 | // We use the error type directly as the type. | 3121 | // We use the error type directly as the type. |
| 3122 | const err_val = if (!is_pl) tv.val else Value.initTag(.zero); | 3122 | const err_val = if (!is_pl) tv.val else Value.initTag(.zero); |
| 3123 | return dg.genTypedValue(.{ .ty = error_type, .val = err_val }); | 3123 | return dg.lowerValue(.{ .ty = error_type, .val = err_val }); |
| 3124 | } | 3124 | } |
| 3125 | | 3125 | |
| 3126 | const payload_align = payload_type.abiAlignment(target); | 3126 | const payload_align = payload_type.abiAlignment(target); |
| 3127 | const error_align = Type.anyerror.abiAlignment(target); | 3127 | const error_align = Type.anyerror.abiAlignment(target); |
| 3128 | const llvm_error_value = try dg.genTypedValue(.{ | 3128 | const llvm_error_value = try dg.lowerValue(.{ |
| 3129 | .ty = error_type, | 3129 | .ty = error_type, |
| 3130 | .val = if (is_pl) Value.initTag(.zero) else tv.val, | 3130 | .val = if (is_pl) Value.initTag(.zero) else tv.val, |
| 3131 | }); | 3131 | }); |
| 3132 | const llvm_payload_value = try dg.genTypedValue(.{ | 3132 | const llvm_payload_value = try dg.lowerValue(.{ |
| 3133 | .ty = payload_type, | 3133 | .ty = payload_type, |
| 3134 | .val = if (tv.val.castTag(.eu_payload)) |pl| pl.data else Value.initTag(.undef), | 3134 | .val = if (tv.val.castTag(.eu_payload)) |pl| pl.data else Value.initTag(.undef), |
| 3135 | }); | 3135 | }); |
| ... | @@ -3142,7 +3142,7 @@ pub const DeclGen = struct { | ... | @@ -3142,7 +3142,7 @@ pub const DeclGen = struct { |
| 3142 | } | 3142 | } |
| 3143 | }, | 3143 | }, |
| 3144 | .Struct => { | 3144 | .Struct => { |
| 3145 | const llvm_struct_ty = try dg.llvmType(tv.ty); | 3145 | const llvm_struct_ty = try dg.lowerType(tv.ty); |
| 3146 | const field_vals = tv.val.castTag(.aggregate).?.data; | 3146 | const field_vals = tv.val.castTag(.aggregate).?.data; |
| 3147 | const gpa = dg.gpa; | 3147 | const gpa = dg.gpa; |
| 3148 | | 3148 | |
| ... | @@ -3175,7 +3175,7 @@ pub const DeclGen = struct { | ... | @@ -3175,7 +3175,7 @@ pub const DeclGen = struct { |
| 3175 | llvm_fields.appendAssumeCapacity(llvm_array_ty.getUndef()); | 3175 | llvm_fields.appendAssumeCapacity(llvm_array_ty.getUndef()); |
| 3176 | } | 3176 | } |
| 3177 | | 3177 | |
| 3178 | const field_llvm_val = try dg.genTypedValue(.{ | 3178 | const field_llvm_val = try dg.lowerValue(.{ |
| 3179 | .ty = field_ty, | 3179 | .ty = field_ty, |
| 3180 | .val = field_vals[i], | 3180 | .val = field_vals[i], |
| 3181 | }); | 3181 | }); |
| ... | @@ -3223,7 +3223,7 @@ pub const DeclGen = struct { | ... | @@ -3223,7 +3223,7 @@ pub const DeclGen = struct { |
| 3223 | const field = fields[i]; | 3223 | const field = fields[i]; |
| 3224 | if (!field.ty.hasRuntimeBitsIgnoreComptime()) continue; | 3224 | if (!field.ty.hasRuntimeBitsIgnoreComptime()) continue; |
| 3225 | | 3225 | |
| 3226 | const non_int_val = try dg.genTypedValue(.{ | 3226 | const non_int_val = try dg.lowerValue(.{ |
| 3227 | .ty = field.ty, | 3227 | .ty = field.ty, |
| 3228 | .val = field_val, | 3228 | .val = field_val, |
| 3229 | }); | 3229 | }); |
| ... | @@ -3267,7 +3267,7 @@ pub const DeclGen = struct { | ... | @@ -3267,7 +3267,7 @@ pub const DeclGen = struct { |
| 3267 | llvm_fields.appendAssumeCapacity(llvm_array_ty.getUndef()); | 3267 | llvm_fields.appendAssumeCapacity(llvm_array_ty.getUndef()); |
| 3268 | } | 3268 | } |
| 3269 | | 3269 | |
| 3270 | const field_llvm_val = try dg.genTypedValue(.{ | 3270 | const field_llvm_val = try dg.lowerValue(.{ |
| 3271 | .ty = field.ty, | 3271 | .ty = field.ty, |
| 3272 | .val = field_vals[i], | 3272 | .val = field_vals[i], |
| 3273 | }); | 3273 | }); |
| ... | @@ -3302,13 +3302,13 @@ pub const DeclGen = struct { | ... | @@ -3302,13 +3302,13 @@ pub const DeclGen = struct { |
| 3302 | } | 3302 | } |
| 3303 | }, | 3303 | }, |
| 3304 | .Union => { | 3304 | .Union => { |
| 3305 | const llvm_union_ty = try dg.llvmType(tv.ty); | 3305 | const llvm_union_ty = try dg.lowerType(tv.ty); |
| 3306 | const tag_and_val = tv.val.castTag(.@"union").?.data; | 3306 | const tag_and_val = tv.val.castTag(.@"union").?.data; |
| 3307 | | 3307 | |
| 3308 | const layout = tv.ty.unionGetLayout(target); | 3308 | const layout = tv.ty.unionGetLayout(target); |
| 3309 | | 3309 | |
| 3310 | if (layout.payload_size == 0) { | 3310 | if (layout.payload_size == 0) { |
| 3311 | return genTypedValue(dg, .{ | 3311 | return lowerValue(dg, .{ |
| 3312 | .ty = tv.ty.unionTagType().?, | 3312 | .ty = tv.ty.unionTagType().?, |
| 3313 | .val = tag_and_val.tag, | 3313 | .val = tag_and_val.tag, |
| 3314 | }); | 3314 | }); |
| ... | @@ -3322,7 +3322,7 @@ pub const DeclGen = struct { | ... | @@ -3322,7 +3322,7 @@ pub const DeclGen = struct { |
| 3322 | const padding_len = @intCast(c_uint, layout.payload_size); | 3322 | const padding_len = @intCast(c_uint, layout.payload_size); |
| 3323 | break :p dg.context.intType(8).arrayType(padding_len).getUndef(); | 3323 | break :p dg.context.intType(8).arrayType(padding_len).getUndef(); |
| 3324 | } | 3324 | } |
| 3325 | const field = try genTypedValue(dg, .{ .ty = field_ty, .val = tag_and_val.val }); | 3325 | const field = try lowerValue(dg, .{ .ty = field_ty, .val = tag_and_val.val }); |
| 3326 | const field_size = field_ty.abiSize(target); | 3326 | const field_size = field_ty.abiSize(target); |
| 3327 | if (field_size == layout.payload_size) { | 3327 | if (field_size == layout.payload_size) { |
| 3328 | break :p field; | 3328 | break :p field; |
| ... | @@ -3348,7 +3348,7 @@ pub const DeclGen = struct { | ... | @@ -3348,7 +3348,7 @@ pub const DeclGen = struct { |
| 3348 | return llvm_union_ty.constNamedStruct(&fields, fields.len); | 3348 | return llvm_union_ty.constNamedStruct(&fields, fields.len); |
| 3349 | } | 3349 | } |
| 3350 | } | 3350 | } |
| 3351 | const llvm_tag_value = try genTypedValue(dg, .{ | 3351 | const llvm_tag_value = try lowerValue(dg, .{ |
| 3352 | .ty = tv.ty.unionTagType().?, | 3352 | .ty = tv.ty.unionTagType().?, |
| 3353 | .val = tag_and_val.tag, | 3353 | .val = tag_and_val.tag, |
| 3354 | }); | 3354 | }); |
| ... | @@ -3385,7 +3385,7 @@ pub const DeclGen = struct { | ... | @@ -3385,7 +3385,7 @@ pub const DeclGen = struct { |
| 3385 | .data = bytes[i], | 3385 | .data = bytes[i], |
| 3386 | }; | 3386 | }; |
| 3387 | | 3387 | |
| 3388 | elem.* = try dg.genTypedValue(.{ | 3388 | elem.* = try dg.lowerValue(.{ |
| 3389 | .ty = elem_ty, | 3389 | .ty = elem_ty, |
| 3390 | .val = Value.initPayload(&byte_payload.base), | 3390 | .val = Value.initPayload(&byte_payload.base), |
| 3391 | }); | 3391 | }); |
| ... | @@ -3405,7 +3405,7 @@ pub const DeclGen = struct { | ... | @@ -3405,7 +3405,7 @@ pub const DeclGen = struct { |
| 3405 | const llvm_elems = try dg.gpa.alloc(*const llvm.Value, vector_len); | 3405 | const llvm_elems = try dg.gpa.alloc(*const llvm.Value, vector_len); |
| 3406 | defer dg.gpa.free(llvm_elems); | 3406 | defer dg.gpa.free(llvm_elems); |
| 3407 | for (llvm_elems) |*elem, i| { | 3407 | for (llvm_elems) |*elem, i| { |
| 3408 | elem.* = try dg.genTypedValue(.{ .ty = elem_ty, .val = elem_vals[i] }); | 3408 | elem.* = try dg.lowerValue(.{ .ty = elem_ty, .val = elem_vals[i] }); |
| 3409 | } | 3409 | } |
| 3410 | return llvm.constVector( | 3410 | return llvm.constVector( |
| 3411 | llvm_elems.ptr, | 3411 | llvm_elems.ptr, |
| ... | @@ -3420,7 +3420,7 @@ pub const DeclGen = struct { | ... | @@ -3420,7 +3420,7 @@ pub const DeclGen = struct { |
| 3420 | const llvm_elems = try dg.gpa.alloc(*const llvm.Value, len); | 3420 | const llvm_elems = try dg.gpa.alloc(*const llvm.Value, len); |
| 3421 | defer dg.gpa.free(llvm_elems); | 3421 | defer dg.gpa.free(llvm_elems); |
| 3422 | for (llvm_elems) |*elem| { | 3422 | for (llvm_elems) |*elem| { |
| 3423 | elem.* = try dg.genTypedValue(.{ .ty = elem_ty, .val = val }); | 3423 | elem.* = try dg.lowerValue(.{ .ty = elem_ty, .val = val }); |
| 3424 | } | 3424 | } |
| 3425 | return llvm.constVector( | 3425 | return llvm.constVector( |
| 3426 | llvm_elems.ptr, | 3426 | llvm_elems.ptr, |
| ... | @@ -3470,7 +3470,7 @@ pub const DeclGen = struct { | ... | @@ -3470,7 +3470,7 @@ pub const DeclGen = struct { |
| 3470 | if (ptr_child_ty.eql(decl.ty, dg.module)) { | 3470 | if (ptr_child_ty.eql(decl.ty, dg.module)) { |
| 3471 | return llvm_ptr; | 3471 | return llvm_ptr; |
| 3472 | } else { | 3472 | } else { |
| 3473 | return llvm_ptr.constBitCast((try dg.llvmType(ptr_child_ty)).pointerType(0)); | 3473 | return llvm_ptr.constBitCast((try dg.lowerType(ptr_child_ty)).pointerType(0)); |
| 3474 | } | 3474 | } |
| 3475 | } | 3475 | } |
| 3476 | | 3476 | |
| ... | @@ -3492,15 +3492,15 @@ pub const DeclGen = struct { | ... | @@ -3492,15 +3492,15 @@ pub const DeclGen = struct { |
| 3492 | }, | 3492 | }, |
| 3493 | .int_i64 => { | 3493 | .int_i64 => { |
| 3494 | const int = ptr_val.castTag(.int_i64).?.data; | 3494 | const int = ptr_val.castTag(.int_i64).?.data; |
| 3495 | const llvm_usize = try dg.llvmType(Type.usize); | 3495 | const llvm_usize = try dg.lowerType(Type.usize); |
| 3496 | const llvm_int = llvm_usize.constInt(@bitCast(u64, int), .False); | 3496 | const llvm_int = llvm_usize.constInt(@bitCast(u64, int), .False); |
| 3497 | return llvm_int.constIntToPtr((try dg.llvmType(ptr_child_ty)).pointerType(0)); | 3497 | return llvm_int.constIntToPtr((try dg.lowerType(ptr_child_ty)).pointerType(0)); |
| 3498 | }, | 3498 | }, |
| 3499 | .int_u64 => { | 3499 | .int_u64 => { |
| 3500 | const int = ptr_val.castTag(.int_u64).?.data; | 3500 | const int = ptr_val.castTag(.int_u64).?.data; |
| 3501 | const llvm_usize = try dg.llvmType(Type.usize); | 3501 | const llvm_usize = try dg.lowerType(Type.usize); |
| 3502 | const llvm_int = llvm_usize.constInt(int, .False); | 3502 | const llvm_int = llvm_usize.constInt(int, .False); |
| 3503 | return llvm_int.constIntToPtr((try dg.llvmType(ptr_child_ty)).pointerType(0)); | 3503 | return llvm_int.constIntToPtr((try dg.lowerType(ptr_child_ty)).pointerType(0)); |
| 3504 | }, | 3504 | }, |
| 3505 | .field_ptr => blk: { | 3505 | .field_ptr => blk: { |
| 3506 | const field_ptr = ptr_val.castTag(.field_ptr).?.data; | 3506 | const field_ptr = ptr_val.castTag(.field_ptr).?.data; |
| ... | @@ -3549,7 +3549,7 @@ pub const DeclGen = struct { | ... | @@ -3549,7 +3549,7 @@ pub const DeclGen = struct { |
| 3549 | const parent_llvm_ptr = try dg.lowerParentPtr(elem_ptr.array_ptr, elem_ptr.elem_ty); | 3549 | const parent_llvm_ptr = try dg.lowerParentPtr(elem_ptr.array_ptr, elem_ptr.elem_ty); |
| 3550 | bitcast_needed = !elem_ptr.elem_ty.eql(ptr_child_ty, dg.module); | 3550 | bitcast_needed = !elem_ptr.elem_ty.eql(ptr_child_ty, dg.module); |
| 3551 | | 3551 | |
| 3552 | const llvm_usize = try dg.llvmType(Type.usize); | 3552 | const llvm_usize = try dg.lowerType(Type.usize); |
| 3553 | const indices: [1]*const llvm.Value = .{ | 3553 | const indices: [1]*const llvm.Value = .{ |
| 3554 | llvm_usize.constInt(elem_ptr.index, .False), | 3554 | llvm_usize.constInt(elem_ptr.index, .False), |
| 3555 | }; | 3555 | }; |
| ... | @@ -3602,7 +3602,7 @@ pub const DeclGen = struct { | ... | @@ -3602,7 +3602,7 @@ pub const DeclGen = struct { |
| 3602 | else => unreachable, | 3602 | else => unreachable, |
| 3603 | }; | 3603 | }; |
| 3604 | if (bitcast_needed) { | 3604 | if (bitcast_needed) { |
| 3605 | return llvm_ptr.constBitCast((try dg.llvmType(ptr_child_ty)).pointerType(0)); | 3605 | return llvm_ptr.constBitCast((try dg.lowerType(ptr_child_ty)).pointerType(0)); |
| 3606 | } else { | 3606 | } else { |
| 3607 | return llvm_ptr; | 3607 | return llvm_ptr; |
| 3608 | } | 3608 | } |
| ... | @@ -3621,11 +3621,11 @@ pub const DeclGen = struct { | ... | @@ -3621,11 +3621,11 @@ pub const DeclGen = struct { |
| 3621 | .data = tv.val.sliceLen(self.module), | 3621 | .data = tv.val.sliceLen(self.module), |
| 3622 | }; | 3622 | }; |
| 3623 | const fields: [2]*const llvm.Value = .{ | 3623 | const fields: [2]*const llvm.Value = .{ |
| 3624 | try self.genTypedValue(.{ | 3624 | try self.lowerValue(.{ |
| 3625 | .ty = ptr_ty, | 3625 | .ty = ptr_ty, |
| 3626 | .val = tv.val, | 3626 | .val = tv.val, |
| 3627 | }), | 3627 | }), |
| 3628 | try self.genTypedValue(.{ | 3628 | try self.lowerValue(.{ |
| 3629 | .ty = Type.usize, | 3629 | .ty = Type.usize, |
| 3630 | .val = Value.initPayload(&slice_len.base), | 3630 | .val = Value.initPayload(&slice_len.base), |
| 3631 | }), | 3631 | }), |
| ... | @@ -3657,7 +3657,7 @@ pub const DeclGen = struct { | ... | @@ -3657,7 +3657,7 @@ pub const DeclGen = struct { |
| 3657 | else | 3657 | else |
| 3658 | try self.resolveGlobalDecl(decl_index); | 3658 | try self.resolveGlobalDecl(decl_index); |
| 3659 | | 3659 | |
| 3660 | const llvm_type = try self.llvmType(tv.ty); | 3660 | const llvm_type = try self.lowerType(tv.ty); |
| 3661 | if (tv.ty.zigTypeTag() == .Int) { | 3661 | if (tv.ty.zigTypeTag() == .Int) { |
| 3662 | return llvm_val.constPtrToInt(llvm_type); | 3662 | return llvm_val.constPtrToInt(llvm_type); |
| 3663 | } else { | 3663 | } else { |
| ... | @@ -3672,8 +3672,8 @@ pub const DeclGen = struct { | ... | @@ -3672,8 +3672,8 @@ pub const DeclGen = struct { |
| 3672 | // The value cannot be undefined, because we use the `nonnull` annotation | 3672 | // The value cannot be undefined, because we use the `nonnull` annotation |
| 3673 | // for non-optional pointers. We also need to respect the alignment, even though | 3673 | // for non-optional pointers. We also need to respect the alignment, even though |
| 3674 | // the address will never be dereferenced. | 3674 | // the address will never be dereferenced. |
| 3675 | const llvm_usize = try dg.llvmType(Type.usize); | 3675 | const llvm_usize = try dg.lowerType(Type.usize); |
| 3676 | const llvm_ptr_ty = try dg.llvmType(ptr_ty); | 3676 | const llvm_ptr_ty = try dg.lowerType(ptr_ty); |
| 3677 | if (alignment != 0) { | 3677 | if (alignment != 0) { |
| 3678 | return llvm_usize.constInt(alignment, .False).constIntToPtr(llvm_ptr_ty); | 3678 | return llvm_usize.constInt(alignment, .False).constIntToPtr(llvm_ptr_ty); |
| 3679 | } | 3679 | } |
| ... | @@ -3852,7 +3852,7 @@ pub const FuncGen = struct { | ... | @@ -3852,7 +3852,7 @@ pub const FuncGen = struct { |
| 3852 | | 3852 | |
| 3853 | const val = self.air.value(inst).?; | 3853 | const val = self.air.value(inst).?; |
| 3854 | const ty = self.air.typeOf(inst); | 3854 | const ty = self.air.typeOf(inst); |
| 3855 | const llvm_val = try self.dg.genTypedValue(.{ .ty = ty, .val = val }); | 3855 | const llvm_val = try self.dg.lowerValue(.{ .ty = ty, .val = val }); |
| 3856 | if (!isByRef(ty)) { | 3856 | if (!isByRef(ty)) { |
| 3857 | gop.value_ptr.* = llvm_val; | 3857 | gop.value_ptr.* = llvm_val; |
| 3858 | return llvm_val; | 3858 | return llvm_val; |
| ... | @@ -3870,7 +3870,7 @@ pub const FuncGen = struct { | ... | @@ -3870,7 +3870,7 @@ pub const FuncGen = struct { |
| 3870 | // Because of LLVM limitations for lowering certain types such as unions, | 3870 | // Because of LLVM limitations for lowering certain types such as unions, |
| 3871 | // the type of global constants might not match the type it is supposed to | 3871 | // the type of global constants might not match the type it is supposed to |
| 3872 | // be, and so we must bitcast the pointer at the usage sites. | 3872 | // be, and so we must bitcast the pointer at the usage sites. |
| 3873 | const wanted_llvm_ty = try self.dg.llvmType(ty); | 3873 | const wanted_llvm_ty = try self.dg.lowerType(ty); |
| 3874 | const wanted_llvm_ptr_ty = wanted_llvm_ty.pointerType(0); | 3874 | const wanted_llvm_ptr_ty = wanted_llvm_ty.pointerType(0); |
| 3875 | const casted_ptr = global.constBitCast(wanted_llvm_ptr_ty); | 3875 | const casted_ptr = global.constBitCast(wanted_llvm_ptr_ty); |
| 3876 | gop.value_ptr.* = casted_ptr; | 3876 | gop.value_ptr.* = casted_ptr; |
| ... | @@ -4094,7 +4094,7 @@ pub const FuncGen = struct { | ... | @@ -4094,7 +4094,7 @@ pub const FuncGen = struct { |
| 4094 | defer llvm_args.deinit(); | 4094 | defer llvm_args.deinit(); |
| 4095 | | 4095 | |
| 4096 | const ret_ptr = if (!sret) null else blk: { | 4096 | const ret_ptr = if (!sret) null else blk: { |
| 4097 | const llvm_ret_ty = try self.dg.llvmType(return_type); | 4097 | const llvm_ret_ty = try self.dg.lowerType(return_type); |
| 4098 | const ret_ptr = self.buildAlloca(llvm_ret_ty); | 4098 | const ret_ptr = self.buildAlloca(llvm_ret_ty); |
| 4099 | ret_ptr.setAlignment(return_type.abiAlignment(target)); | 4099 | ret_ptr.setAlignment(return_type.abiAlignment(target)); |
| 4100 | try llvm_args.append(ret_ptr); | 4100 | try llvm_args.append(ret_ptr); |
| ... | @@ -4126,7 +4126,7 @@ pub const FuncGen = struct { | ... | @@ -4126,7 +4126,7 @@ pub const FuncGen = struct { |
| 4126 | // which is always lowered to an LLVM type of `*i8`. | 4126 | // which is always lowered to an LLVM type of `*i8`. |
| 4127 | // 2. The argument is a global which does act as a pointer, however | 4127 | // 2. The argument is a global which does act as a pointer, however |
| 4128 | // a bitcast is needed in order for the LLVM types to match. | 4128 | // a bitcast is needed in order for the LLVM types to match. |
| 4129 | const llvm_param_ty = try self.dg.llvmType(param_ty); | 4129 | const llvm_param_ty = try self.dg.lowerType(param_ty); |
| 4130 | const casted_ptr = self.builder.buildBitCast(llvm_arg, llvm_param_ty, ""); | 4130 | const casted_ptr = self.builder.buildBitCast(llvm_arg, llvm_param_ty, ""); |
| 4131 | try llvm_args.append(casted_ptr); | 4131 | try llvm_args.append(casted_ptr); |
| 4132 | } else { | 4132 | } else { |
| ... | @@ -4173,7 +4173,7 @@ pub const FuncGen = struct { | ... | @@ -4173,7 +4173,7 @@ pub const FuncGen = struct { |
| 4173 | ); | 4173 | ); |
| 4174 | const int_ptr = self.buildAlloca(int_llvm_ty); | 4174 | const int_ptr = self.buildAlloca(int_llvm_ty); |
| 4175 | int_ptr.setAlignment(alignment); | 4175 | int_ptr.setAlignment(alignment); |
| 4176 | const param_llvm_ty = try self.dg.llvmType(param_ty); | 4176 | const param_llvm_ty = try self.dg.lowerType(param_ty); |
| 4177 | const casted_ptr = self.builder.buildBitCast(int_ptr, param_llvm_ty.pointerType(0), ""); | 4177 | const casted_ptr = self.builder.buildBitCast(int_ptr, param_llvm_ty.pointerType(0), ""); |
| 4178 | const store_inst = self.builder.buildStore(llvm_arg, casted_ptr); | 4178 | const store_inst = self.builder.buildStore(llvm_arg, casted_ptr); |
| 4179 | store_inst.setAlignment(alignment); | 4179 | store_inst.setAlignment(alignment); |
| ... | @@ -4284,7 +4284,7 @@ pub const FuncGen = struct { | ... | @@ -4284,7 +4284,7 @@ pub const FuncGen = struct { |
| 4284 | return null; | 4284 | return null; |
| 4285 | } | 4285 | } |
| 4286 | | 4286 | |
| 4287 | const llvm_ret_ty = try self.dg.llvmType(return_type); | 4287 | const llvm_ret_ty = try self.dg.lowerType(return_type); |
| 4288 | | 4288 | |
| 4289 | if (ret_ptr) |rp| { | 4289 | if (ret_ptr) |rp| { |
| 4290 | call.setCallSret(llvm_ret_ty); | 4290 | call.setCallSret(llvm_ret_ty); |
| ... | @@ -4354,7 +4354,7 @@ pub const FuncGen = struct { | ... | @@ -4354,7 +4354,7 @@ pub const FuncGen = struct { |
| 4354 | // Functions with an empty error set are emitted with an error code | 4354 | // Functions with an empty error set are emitted with an error code |
| 4355 | // return type and return zero so they can be function pointers coerced | 4355 | // return type and return zero so they can be function pointers coerced |
| 4356 | // to functions that return anyerror. | 4356 | // to functions that return anyerror. |
| 4357 | const err_int = try self.dg.llvmType(Type.anyerror); | 4357 | const err_int = try self.dg.lowerType(Type.anyerror); |
| 4358 | _ = self.builder.buildRet(err_int.constInt(0, .False)); | 4358 | _ = self.builder.buildRet(err_int.constInt(0, .False)); |
| 4359 | } else { | 4359 | } else { |
| 4360 | _ = self.builder.buildRetVoid(); | 4360 | _ = self.builder.buildRetVoid(); |
| ... | @@ -4393,7 +4393,7 @@ pub const FuncGen = struct { | ... | @@ -4393,7 +4393,7 @@ pub const FuncGen = struct { |
| 4393 | // Functions with an empty error set are emitted with an error code | 4393 | // Functions with an empty error set are emitted with an error code |
| 4394 | // return type and return zero so they can be function pointers coerced | 4394 | // return type and return zero so they can be function pointers coerced |
| 4395 | // to functions that return anyerror. | 4395 | // to functions that return anyerror. |
| 4396 | const err_int = try self.dg.llvmType(Type.anyerror); | 4396 | const err_int = try self.dg.lowerType(Type.anyerror); |
| 4397 | _ = self.builder.buildRet(err_int.constInt(0, .False)); | 4397 | _ = self.builder.buildRet(err_int.constInt(0, .False)); |
| 4398 | } else { | 4398 | } else { |
| 4399 | _ = self.builder.buildRetVoid(); | 4399 | _ = self.builder.buildRetVoid(); |
| ... | @@ -4407,7 +4407,7 @@ pub const FuncGen = struct { | ... | @@ -4407,7 +4407,7 @@ pub const FuncGen = struct { |
| 4407 | const ptr = try self.resolveInst(un_op); | 4407 | const ptr = try self.resolveInst(un_op); |
| 4408 | const target = self.dg.module.getTarget(); | 4408 | const target = self.dg.module.getTarget(); |
| 4409 | const abi_ret_ty = try lowerFnRetTy(self.dg, fn_info); | 4409 | const abi_ret_ty = try lowerFnRetTy(self.dg, fn_info); |
| 4410 | const llvm_ret_ty = try self.dg.llvmType(ret_ty); | 4410 | const llvm_ret_ty = try self.dg.lowerType(ret_ty); |
| 4411 | const casted_ptr = if (abi_ret_ty == llvm_ret_ty) ptr else p: { | 4411 | const casted_ptr = if (abi_ret_ty == llvm_ret_ty) ptr else p: { |
| 4412 | const ptr_abi_ty = abi_ret_ty.pointerType(0); | 4412 | const ptr_abi_ty = abi_ret_ty.pointerType(0); |
| 4413 | break :p self.builder.buildBitCast(ptr, ptr_abi_ty, ""); | 4413 | break :p self.builder.buildBitCast(ptr, ptr_abi_ty, ""); |
| ... | @@ -4588,7 +4588,7 @@ pub const FuncGen = struct { | ... | @@ -4588,7 +4588,7 @@ pub const FuncGen = struct { |
| 4588 | const is_body = inst_ty.zigTypeTag() == .Fn; | 4588 | const is_body = inst_ty.zigTypeTag() == .Fn; |
| 4589 | if (!is_body and !inst_ty.hasRuntimeBitsIgnoreComptime()) return null; | 4589 | if (!is_body and !inst_ty.hasRuntimeBitsIgnoreComptime()) return null; |
| 4590 | | 4590 | |
| 4591 | const raw_llvm_ty = try self.dg.llvmType(inst_ty); | 4591 | const raw_llvm_ty = try self.dg.lowerType(inst_ty); |
| 4592 | | 4592 | |
| 4593 | const llvm_ty = ty: { | 4593 | const llvm_ty = ty: { |
| 4594 | // If the zig tag type is a function, this represents an actual function body; not | 4594 | // If the zig tag type is a function, this represents an actual function body; not |
| ... | @@ -4728,9 +4728,9 @@ pub const FuncGen = struct { | ... | @@ -4728,9 +4728,9 @@ pub const FuncGen = struct { |
| 4728 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | 4728 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; |
| 4729 | const operand_ty = self.air.typeOf(ty_op.operand); | 4729 | const operand_ty = self.air.typeOf(ty_op.operand); |
| 4730 | const array_ty = operand_ty.childType(); | 4730 | const array_ty = operand_ty.childType(); |
| 4731 | const llvm_usize = try self.dg.llvmType(Type.usize); | 4731 | const llvm_usize = try self.dg.lowerType(Type.usize); |
| 4732 | const len = llvm_usize.constInt(array_ty.arrayLen(), .False); | 4732 | const len = llvm_usize.constInt(array_ty.arrayLen(), .False); |
| 4733 | const slice_llvm_ty = try self.dg.llvmType(self.air.typeOfIndex(inst)); | 4733 | const slice_llvm_ty = try self.dg.lowerType(self.air.typeOfIndex(inst)); |
| 4734 | if (!array_ty.hasRuntimeBitsIgnoreComptime()) { | 4734 | if (!array_ty.hasRuntimeBitsIgnoreComptime()) { |
| 4735 | return self.builder.buildInsertValue(slice_llvm_ty.getUndef(), len, 1, ""); | 4735 | return self.builder.buildInsertValue(slice_llvm_ty.getUndef(), len, 1, ""); |
| 4736 | } | 4736 | } |
| ... | @@ -4755,7 +4755,7 @@ pub const FuncGen = struct { | ... | @@ -4755,7 +4755,7 @@ pub const FuncGen = struct { |
| 4755 | | 4755 | |
| 4756 | const dest_ty = self.air.typeOfIndex(inst); | 4756 | const dest_ty = self.air.typeOfIndex(inst); |
| 4757 | const dest_scalar_ty = dest_ty.scalarType(); | 4757 | const dest_scalar_ty = dest_ty.scalarType(); |
| 4758 | const dest_llvm_ty = try self.dg.llvmType(dest_ty); | 4758 | const dest_llvm_ty = try self.dg.lowerType(dest_ty); |
| 4759 | const target = self.dg.module.getTarget(); | 4759 | const target = self.dg.module.getTarget(); |
| 4760 | | 4760 | |
| 4761 | if (intrinsicsAllowed(dest_scalar_ty, target)) { | 4761 | if (intrinsicsAllowed(dest_scalar_ty, target)) { |
| ... | @@ -4806,7 +4806,7 @@ pub const FuncGen = struct { | ... | @@ -4806,7 +4806,7 @@ pub const FuncGen = struct { |
| 4806 | | 4806 | |
| 4807 | const dest_ty = self.air.typeOfIndex(inst); | 4807 | const dest_ty = self.air.typeOfIndex(inst); |
| 4808 | const dest_scalar_ty = dest_ty.scalarType(); | 4808 | const dest_scalar_ty = dest_ty.scalarType(); |
| 4809 | const dest_llvm_ty = try self.dg.llvmType(dest_ty); | 4809 | const dest_llvm_ty = try self.dg.lowerType(dest_ty); |
| 4810 | | 4810 | |
| 4811 | if (intrinsicsAllowed(operand_scalar_ty, target)) { | 4811 | if (intrinsicsAllowed(operand_scalar_ty, target)) { |
| 4812 | // TODO set fast math flag | 4812 | // TODO set fast math flag |
| ... | @@ -4833,7 +4833,7 @@ pub const FuncGen = struct { | ... | @@ -4833,7 +4833,7 @@ pub const FuncGen = struct { |
| 4833 | compiler_rt_dest_abbrev, | 4833 | compiler_rt_dest_abbrev, |
| 4834 | }) catch unreachable; | 4834 | }) catch unreachable; |
| 4835 | | 4835 | |
| 4836 | const operand_llvm_ty = try self.dg.llvmType(operand_ty); | 4836 | const operand_llvm_ty = try self.dg.lowerType(operand_ty); |
| 4837 | const param_types = [1]*const llvm.Type{operand_llvm_ty}; | 4837 | const param_types = [1]*const llvm.Type{operand_llvm_ty}; |
| 4838 | const libc_fn = self.getLibcFunction(fn_name, &param_types, libc_ret_ty); | 4838 | const libc_fn = self.getLibcFunction(fn_name, &param_types, libc_ret_ty); |
| 4839 | const params = [1]*const llvm.Value{operand}; | 4839 | const params = [1]*const llvm.Value{operand}; |
| ... | @@ -4994,7 +4994,7 @@ pub const FuncGen = struct { | ... | @@ -4994,7 +4994,7 @@ pub const FuncGen = struct { |
| 4994 | const containing_int = struct_llvm_val; | 4994 | const containing_int = struct_llvm_val; |
| 4995 | const shift_amt = containing_int.typeOf().constInt(bit_offset, .False); | 4995 | const shift_amt = containing_int.typeOf().constInt(bit_offset, .False); |
| 4996 | const shifted_value = self.builder.buildLShr(containing_int, shift_amt, ""); | 4996 | const shifted_value = self.builder.buildLShr(containing_int, shift_amt, ""); |
| 4997 | const elem_llvm_ty = try self.dg.llvmType(field_ty); | 4997 | const elem_llvm_ty = try self.dg.lowerType(field_ty); |
| 4998 | if (field_ty.zigTypeTag() == .Float) { | 4998 | if (field_ty.zigTypeTag() == .Float) { |
| 4999 | const elem_bits = @intCast(c_uint, field_ty.bitSize(target)); | 4999 | const elem_bits = @intCast(c_uint, field_ty.bitSize(target)); |
| 5000 | const same_size_int = self.context.intType(elem_bits); | 5000 | const same_size_int = self.context.intType(elem_bits); |
| ... | @@ -5026,7 +5026,7 @@ pub const FuncGen = struct { | ... | @@ -5026,7 +5026,7 @@ pub const FuncGen = struct { |
| 5026 | return self.load(field_ptr, field_ptr_ty); | 5026 | return self.load(field_ptr, field_ptr_ty); |
| 5027 | }, | 5027 | }, |
| 5028 | .Union => { | 5028 | .Union => { |
| 5029 | const llvm_field_ty = try self.dg.llvmType(field_ty); | 5029 | const llvm_field_ty = try self.dg.lowerType(field_ty); |
| 5030 | const layout = struct_ty.unionGetLayout(target); | 5030 | const layout = struct_ty.unionGetLayout(target); |
| 5031 | const payload_index = @boolToInt(layout.tag_align >= layout.payload_align); | 5031 | const payload_index = @boolToInt(layout.tag_align >= layout.payload_align); |
| 5032 | const union_field_ptr = self.builder.buildStructGEP(struct_llvm_val, payload_index, ""); | 5032 | const union_field_ptr = self.builder.buildStructGEP(struct_llvm_val, payload_index, ""); |
| ... | @@ -5053,7 +5053,7 @@ pub const FuncGen = struct { | ... | @@ -5053,7 +5053,7 @@ pub const FuncGen = struct { |
| 5053 | const struct_ty = self.air.getRefType(ty_pl.ty).childType(); | 5053 | const struct_ty = self.air.getRefType(ty_pl.ty).childType(); |
| 5054 | const field_offset = struct_ty.structFieldOffset(extra.field_index, target); | 5054 | const field_offset = struct_ty.structFieldOffset(extra.field_index, target); |
| 5055 | | 5055 | |
| 5056 | const res_ty = try self.dg.llvmType(self.air.getRefType(ty_pl.ty)); | 5056 | const res_ty = try self.dg.lowerType(self.air.getRefType(ty_pl.ty)); |
| 5057 | if (field_offset == 0) { | 5057 | if (field_offset == 0) { |
| 5058 | return self.builder.buildBitCast(field_ptr, res_ty, ""); | 5058 | return self.builder.buildBitCast(field_ptr, res_ty, ""); |
| 5059 | } | 5059 | } |
| ... | @@ -5383,7 +5383,7 @@ pub const FuncGen = struct { | ... | @@ -5383,7 +5383,7 @@ pub const FuncGen = struct { |
| 5383 | } | 5383 | } |
| 5384 | | 5384 | |
| 5385 | const ret_ty = self.air.typeOfIndex(inst); | 5385 | const ret_ty = self.air.typeOfIndex(inst); |
| 5386 | const ret_llvm_ty = try self.dg.llvmType(ret_ty); | 5386 | const ret_llvm_ty = try self.dg.lowerType(ret_ty); |
| 5387 | const llvm_fn_ty = llvm.functionType( | 5387 | const llvm_fn_ty = llvm.functionType( |
| 5388 | ret_llvm_ty, | 5388 | ret_llvm_ty, |
| 5389 | llvm_param_types.ptr, | 5389 | llvm_param_types.ptr, |
| ... | @@ -5425,7 +5425,7 @@ pub const FuncGen = struct { | ... | @@ -5425,7 +5425,7 @@ pub const FuncGen = struct { |
| 5425 | const operand_ty = self.air.typeOf(un_op); | 5425 | const operand_ty = self.air.typeOf(un_op); |
| 5426 | const optional_ty = if (operand_is_ptr) operand_ty.childType() else operand_ty; | 5426 | const optional_ty = if (operand_is_ptr) operand_ty.childType() else operand_ty; |
| 5427 | if (optional_ty.optionalReprIsPayload()) { | 5427 | if (optional_ty.optionalReprIsPayload()) { |
| 5428 | const optional_llvm_ty = try self.dg.llvmType(optional_ty); | 5428 | const optional_llvm_ty = try self.dg.lowerType(optional_ty); |
| 5429 | const loaded = if (operand_is_ptr) self.builder.buildLoad(operand, "") else operand; | 5429 | const loaded = if (operand_is_ptr) self.builder.buildLoad(operand, "") else operand; |
| 5430 | return self.builder.buildICmp(pred, loaded, optional_llvm_ty.constNull(), ""); | 5430 | return self.builder.buildICmp(pred, loaded, optional_llvm_ty.constNull(), ""); |
| 5431 | } | 5431 | } |
| ... | @@ -5462,7 +5462,7 @@ pub const FuncGen = struct { | ... | @@ -5462,7 +5462,7 @@ pub const FuncGen = struct { |
| 5462 | const operand = try self.resolveInst(un_op); | 5462 | const operand = try self.resolveInst(un_op); |
| 5463 | const err_union_ty = self.air.typeOf(un_op); | 5463 | const err_union_ty = self.air.typeOf(un_op); |
| 5464 | const payload_ty = err_union_ty.errorUnionPayload(); | 5464 | const payload_ty = err_union_ty.errorUnionPayload(); |
| 5465 | const err_set_ty = try self.dg.llvmType(Type.initTag(.anyerror)); | 5465 | const err_set_ty = try self.dg.lowerType(Type.initTag(.anyerror)); |
| 5466 | const zero = err_set_ty.constNull(); | 5466 | const zero = err_set_ty.constNull(); |
| 5467 | | 5467 | |
| 5468 | if (err_union_ty.errorUnionSet().errorSetCardinality() == .zero) { | 5468 | if (err_union_ty.errorUnionSet().errorSetCardinality() == .zero) { |
| ... | @@ -5506,7 +5506,7 @@ pub const FuncGen = struct { | ... | @@ -5506,7 +5506,7 @@ pub const FuncGen = struct { |
| 5506 | // a pointer to a zero-bit value. | 5506 | // a pointer to a zero-bit value. |
| 5507 | | 5507 | |
| 5508 | // TODO once we update to LLVM 14 this bitcast won't be necessary. | 5508 | // TODO once we update to LLVM 14 this bitcast won't be necessary. |
| 5509 | const res_ptr_ty = try self.dg.llvmType(result_ty); | 5509 | const res_ptr_ty = try self.dg.lowerType(result_ty); |
| 5510 | return self.builder.buildBitCast(operand, res_ptr_ty, ""); | 5510 | return self.builder.buildBitCast(operand, res_ptr_ty, ""); |
| 5511 | } | 5511 | } |
| 5512 | if (optional_ty.optionalReprIsPayload()) { | 5512 | if (optional_ty.optionalReprIsPayload()) { |
| ... | @@ -5534,7 +5534,7 @@ pub const FuncGen = struct { | ... | @@ -5534,7 +5534,7 @@ pub const FuncGen = struct { |
| 5534 | _ = self.builder.buildStore(non_null_bit, operand); | 5534 | _ = self.builder.buildStore(non_null_bit, operand); |
| 5535 | | 5535 | |
| 5536 | // TODO once we update to LLVM 14 this bitcast won't be necessary. | 5536 | // TODO once we update to LLVM 14 this bitcast won't be necessary. |
| 5537 | const res_ptr_ty = try self.dg.llvmType(result_ty); | 5537 | const res_ptr_ty = try self.dg.lowerType(result_ty); |
| 5538 | return self.builder.buildBitCast(operand, res_ptr_ty, ""); | 5538 | return self.builder.buildBitCast(operand, res_ptr_ty, ""); |
| 5539 | } | 5539 | } |
| 5540 | if (optional_ty.optionalReprIsPayload()) { | 5540 | if (optional_ty.optionalReprIsPayload()) { |
| ... | @@ -5604,7 +5604,7 @@ pub const FuncGen = struct { | ... | @@ -5604,7 +5604,7 @@ pub const FuncGen = struct { |
| 5604 | if (!operand_is_ptr) return null; | 5604 | if (!operand_is_ptr) return null; |
| 5605 | | 5605 | |
| 5606 | // TODO once we update to LLVM 14 this bitcast won't be necessary. | 5606 | // TODO once we update to LLVM 14 this bitcast won't be necessary. |
| 5607 | const res_ptr_ty = try self.dg.llvmType(result_ty); | 5607 | const res_ptr_ty = try self.dg.lowerType(result_ty); |
| 5608 | return self.builder.buildBitCast(operand, res_ptr_ty, ""); | 5608 | return self.builder.buildBitCast(operand, res_ptr_ty, ""); |
| 5609 | } | 5609 | } |
| 5610 | if (operand_is_ptr or isByRef(payload_ty)) { | 5610 | if (operand_is_ptr or isByRef(payload_ty)) { |
| ... | @@ -5626,7 +5626,7 @@ pub const FuncGen = struct { | ... | @@ -5626,7 +5626,7 @@ pub const FuncGen = struct { |
| 5626 | const operand_ty = self.air.typeOf(ty_op.operand); | 5626 | const operand_ty = self.air.typeOf(ty_op.operand); |
| 5627 | const err_union_ty = if (operand_is_ptr) operand_ty.childType() else operand_ty; | 5627 | const err_union_ty = if (operand_is_ptr) operand_ty.childType() else operand_ty; |
| 5628 | if (err_union_ty.errorUnionSet().errorSetCardinality() == .zero) { | 5628 | if (err_union_ty.errorUnionSet().errorSetCardinality() == .zero) { |
| 5629 | const err_llvm_ty = try self.dg.llvmType(Type.anyerror); | 5629 | const err_llvm_ty = try self.dg.lowerType(Type.anyerror); |
| 5630 | if (operand_is_ptr) { | 5630 | if (operand_is_ptr) { |
| 5631 | return self.builder.buildBitCast(operand, err_llvm_ty.pointerType(0), ""); | 5631 | return self.builder.buildBitCast(operand, err_llvm_ty.pointerType(0), ""); |
| 5632 | } else { | 5632 | } else { |
| ... | @@ -5662,7 +5662,7 @@ pub const FuncGen = struct { | ... | @@ -5662,7 +5662,7 @@ pub const FuncGen = struct { |
| 5662 | return operand; | 5662 | return operand; |
| 5663 | } | 5663 | } |
| 5664 | const payload_ty = error_union_ty.errorUnionPayload(); | 5664 | const payload_ty = error_union_ty.errorUnionPayload(); |
| 5665 | const non_error_val = try self.dg.genTypedValue(.{ .ty = error_ty, .val = Value.zero }); | 5665 | const non_error_val = try self.dg.lowerValue(.{ .ty = error_ty, .val = Value.zero }); |
| 5666 | if (!payload_ty.hasRuntimeBitsIgnoreComptime()) { | 5666 | if (!payload_ty.hasRuntimeBitsIgnoreComptime()) { |
| 5667 | _ = self.builder.buildStore(non_error_val, operand); | 5667 | _ = self.builder.buildStore(non_error_val, operand); |
| 5668 | return operand; | 5668 | return operand; |
| ... | @@ -5715,7 +5715,7 @@ pub const FuncGen = struct { | ... | @@ -5715,7 +5715,7 @@ pub const FuncGen = struct { |
| 5715 | if (optional_ty.optionalReprIsPayload()) { | 5715 | if (optional_ty.optionalReprIsPayload()) { |
| 5716 | return operand; | 5716 | return operand; |
| 5717 | } | 5717 | } |
| 5718 | const llvm_optional_ty = try self.dg.llvmType(optional_ty); | 5718 | const llvm_optional_ty = try self.dg.lowerType(optional_ty); |
| 5719 | if (isByRef(optional_ty)) { | 5719 | if (isByRef(optional_ty)) { |
| 5720 | const optional_ptr = self.buildAlloca(llvm_optional_ty); | 5720 | const optional_ptr = self.buildAlloca(llvm_optional_ty); |
| 5721 | const payload_ptr = self.builder.buildStructGEP(optional_ptr, 0, ""); | 5721 | const payload_ptr = self.builder.buildStructGEP(optional_ptr, 0, ""); |
| ... | @@ -5746,8 +5746,8 @@ pub const FuncGen = struct { | ... | @@ -5746,8 +5746,8 @@ pub const FuncGen = struct { |
| 5746 | if (!payload_ty.hasRuntimeBitsIgnoreComptime()) { | 5746 | if (!payload_ty.hasRuntimeBitsIgnoreComptime()) { |
| 5747 | return operand; | 5747 | return operand; |
| 5748 | } | 5748 | } |
| 5749 | const ok_err_code = (try self.dg.llvmType(Type.anyerror)).constNull(); | 5749 | const ok_err_code = (try self.dg.lowerType(Type.anyerror)).constNull(); |
| 5750 | const err_un_llvm_ty = try self.dg.llvmType(inst_ty); | 5750 | const err_un_llvm_ty = try self.dg.lowerType(inst_ty); |
| 5751 | | 5751 | |
| 5752 | const target = self.dg.module.getTarget(); | 5752 | const target = self.dg.module.getTarget(); |
| 5753 | const payload_offset = errUnionPayloadOffset(payload_ty, target); | 5753 | const payload_offset = errUnionPayloadOffset(payload_ty, target); |
| ... | @@ -5781,7 +5781,7 @@ pub const FuncGen = struct { | ... | @@ -5781,7 +5781,7 @@ pub const FuncGen = struct { |
| 5781 | if (!payload_ty.hasRuntimeBitsIgnoreComptime()) { | 5781 | if (!payload_ty.hasRuntimeBitsIgnoreComptime()) { |
| 5782 | return operand; | 5782 | return operand; |
| 5783 | } | 5783 | } |
| 5784 | const err_un_llvm_ty = try self.dg.llvmType(err_un_ty); | 5784 | const err_un_llvm_ty = try self.dg.lowerType(err_un_ty); |
| 5785 | | 5785 | |
| 5786 | const target = self.dg.module.getTarget(); | 5786 | const target = self.dg.module.getTarget(); |
| 5787 | const payload_offset = errUnionPayloadOffset(payload_ty, target); | 5787 | const payload_offset = errUnionPayloadOffset(payload_ty, target); |
| ... | @@ -5866,7 +5866,7 @@ pub const FuncGen = struct { | ... | @@ -5866,7 +5866,7 @@ pub const FuncGen = struct { |
| 5866 | const ptr = try self.resolveInst(bin_op.lhs); | 5866 | const ptr = try self.resolveInst(bin_op.lhs); |
| 5867 | const len = try self.resolveInst(bin_op.rhs); | 5867 | const len = try self.resolveInst(bin_op.rhs); |
| 5868 | const inst_ty = self.air.typeOfIndex(inst); | 5868 | const inst_ty = self.air.typeOfIndex(inst); |
| 5869 | const llvm_slice_ty = try self.dg.llvmType(inst_ty); | 5869 | const llvm_slice_ty = try self.dg.lowerType(inst_ty); |
| 5870 | | 5870 | |
| 5871 | // In case of slicing a global, the result type looks something like `{ i8*, i64 }` | 5871 | // In case of slicing a global, the result type looks something like `{ i8*, i64 }` |
| 5872 | // but `ptr` is pointing to the global directly. If it's an array, we would want to | 5872 | // but `ptr` is pointing to the global directly. If it's an array, we would want to |
| ... | @@ -5874,7 +5874,7 @@ pub const FuncGen = struct { | ... | @@ -5874,7 +5874,7 @@ pub const FuncGen = struct { |
| 5874 | // This prevents an assertion failure. | 5874 | // This prevents an assertion failure. |
| 5875 | var buf: Type.SlicePtrFieldTypeBuffer = undefined; | 5875 | var buf: Type.SlicePtrFieldTypeBuffer = undefined; |
| 5876 | const ptr_ty = inst_ty.slicePtrFieldType(&buf); | 5876 | const ptr_ty = inst_ty.slicePtrFieldType(&buf); |
| 5877 | const ptr_llvm_ty = try self.dg.llvmType(ptr_ty); | 5877 | const ptr_llvm_ty = try self.dg.lowerType(ptr_ty); |
| 5878 | const casted_ptr = self.builder.buildBitCast(ptr, ptr_llvm_ty, ""); | 5878 | const casted_ptr = self.builder.buildBitCast(ptr, ptr_llvm_ty, ""); |
| 5879 | const partial = self.builder.buildInsertValue(llvm_slice_ty.getUndef(), casted_ptr, 0, ""); | 5879 | const partial = self.builder.buildInsertValue(llvm_slice_ty.getUndef(), casted_ptr, 0, ""); |
| 5880 | return self.builder.buildInsertValue(partial, len, 1, ""); | 5880 | return self.builder.buildInsertValue(partial, len, 1, ""); |
| ... | @@ -6040,7 +6040,7 @@ pub const FuncGen = struct { | ... | @@ -6040,7 +6040,7 @@ pub const FuncGen = struct { |
| 6040 | // const d = @divTrunc(a, b); | 6040 | // const d = @divTrunc(a, b); |
| 6041 | // const r = @rem(a, b); | 6041 | // const r = @rem(a, b); |
| 6042 | // return if (r == 0) d else d - ((a < 0) ^ (b < 0)); | 6042 | // return if (r == 0) d else d - ((a < 0) ^ (b < 0)); |
| 6043 | const result_llvm_ty = try self.dg.llvmType(inst_ty); | 6043 | const result_llvm_ty = try self.dg.lowerType(inst_ty); |
| 6044 | const zero = result_llvm_ty.constNull(); | 6044 | const zero = result_llvm_ty.constNull(); |
| 6045 | const div_trunc = self.builder.buildSDiv(lhs, rhs, ""); | 6045 | const div_trunc = self.builder.buildSDiv(lhs, rhs, ""); |
| 6046 | const rem = self.builder.buildSRem(lhs, rhs, ""); | 6046 | const rem = self.builder.buildSRem(lhs, rhs, ""); |
| ... | @@ -6090,7 +6090,7 @@ pub const FuncGen = struct { | ... | @@ -6090,7 +6090,7 @@ pub const FuncGen = struct { |
| 6090 | const lhs = try self.resolveInst(bin_op.lhs); | 6090 | const lhs = try self.resolveInst(bin_op.lhs); |
| 6091 | const rhs = try self.resolveInst(bin_op.rhs); | 6091 | const rhs = try self.resolveInst(bin_op.rhs); |
| 6092 | const inst_ty = self.air.typeOfIndex(inst); | 6092 | const inst_ty = self.air.typeOfIndex(inst); |
| 6093 | const inst_llvm_ty = try self.dg.llvmType(inst_ty); | 6093 | const inst_llvm_ty = try self.dg.lowerType(inst_ty); |
| 6094 | const scalar_ty = inst_ty.scalarType(); | 6094 | const scalar_ty = inst_ty.scalarType(); |
| 6095 | | 6095 | |
| 6096 | if (scalar_ty.isRuntimeFloat()) { | 6096 | if (scalar_ty.isRuntimeFloat()) { |
| ... | @@ -6174,8 +6174,8 @@ pub const FuncGen = struct { | ... | @@ -6174,8 +6174,8 @@ pub const FuncGen = struct { |
| 6174 | | 6174 | |
| 6175 | const intrinsic_name = if (scalar_ty.isSignedInt()) signed_intrinsic else unsigned_intrinsic; | 6175 | const intrinsic_name = if (scalar_ty.isSignedInt()) signed_intrinsic else unsigned_intrinsic; |
| 6176 | | 6176 | |
| 6177 | const llvm_lhs_ty = try self.dg.llvmType(lhs_ty); | 6177 | const llvm_lhs_ty = try self.dg.lowerType(lhs_ty); |
| 6178 | const llvm_dest_ty = try self.dg.llvmType(dest_ty); | 6178 | const llvm_dest_ty = try self.dg.lowerType(dest_ty); |
| 6179 | | 6179 | |
| 6180 | const tg = self.dg.module.getTarget(); | 6180 | const tg = self.dg.module.getTarget(); |
| 6181 | | 6181 | |
| ... | @@ -6283,7 +6283,7 @@ pub const FuncGen = struct { | ... | @@ -6283,7 +6283,7 @@ pub const FuncGen = struct { |
| 6283 | ) !*const llvm.Value { | 6283 | ) !*const llvm.Value { |
| 6284 | const target = self.dg.module.getTarget(); | 6284 | const target = self.dg.module.getTarget(); |
| 6285 | const scalar_ty = ty.scalarType(); | 6285 | const scalar_ty = ty.scalarType(); |
| 6286 | const scalar_llvm_ty = try self.dg.llvmType(scalar_ty); | 6286 | const scalar_llvm_ty = try self.dg.lowerType(scalar_ty); |
| 6287 | | 6287 | |
| 6288 | if (intrinsicsAllowed(scalar_ty, target)) { | 6288 | if (intrinsicsAllowed(scalar_ty, target)) { |
| 6289 | const llvm_predicate: llvm.RealPredicate = switch (pred) { | 6289 | const llvm_predicate: llvm.RealPredicate = switch (pred) { |
| ... | @@ -6383,8 +6383,8 @@ pub const FuncGen = struct { | ... | @@ -6383,8 +6383,8 @@ pub const FuncGen = struct { |
| 6383 | ) !*const llvm.Value { | 6383 | ) !*const llvm.Value { |
| 6384 | const target = self.dg.module.getTarget(); | 6384 | const target = self.dg.module.getTarget(); |
| 6385 | const scalar_ty = ty.scalarType(); | 6385 | const scalar_ty = ty.scalarType(); |
| 6386 | const llvm_ty = try self.dg.llvmType(ty); | 6386 | const llvm_ty = try self.dg.lowerType(ty); |
| 6387 | const scalar_llvm_ty = try self.dg.llvmType(scalar_ty); | 6387 | const scalar_llvm_ty = try self.dg.lowerType(scalar_ty); |
| 6388 | | 6388 | |
| 6389 | const intrinsics_allowed = op != .tan and intrinsicsAllowed(scalar_ty, target); | 6389 | const intrinsics_allowed = op != .tan and intrinsicsAllowed(scalar_ty, target); |
| 6390 | var fn_name_buf: [64]u8 = undefined; | 6390 | var fn_name_buf: [64]u8 = undefined; |
| ... | @@ -6478,12 +6478,12 @@ pub const FuncGen = struct { | ... | @@ -6478,12 +6478,12 @@ pub const FuncGen = struct { |
| 6478 | const rhs_scalar_ty = rhs_ty.scalarType(); | 6478 | const rhs_scalar_ty = rhs_ty.scalarType(); |
| 6479 | | 6479 | |
| 6480 | const dest_ty = self.air.typeOfIndex(inst); | 6480 | const dest_ty = self.air.typeOfIndex(inst); |
| 6481 | const llvm_dest_ty = try self.dg.llvmType(dest_ty); | 6481 | const llvm_dest_ty = try self.dg.lowerType(dest_ty); |
| 6482 | | 6482 | |
| 6483 | const tg = self.dg.module.getTarget(); | 6483 | const tg = self.dg.module.getTarget(); |
| 6484 | | 6484 | |
| 6485 | const casted_rhs = if (rhs_scalar_ty.bitSize(tg) < lhs_scalar_ty.bitSize(tg)) | 6485 | const casted_rhs = if (rhs_scalar_ty.bitSize(tg) < lhs_scalar_ty.bitSize(tg)) |
| 6486 | self.builder.buildZExt(rhs, try self.dg.llvmType(lhs_ty), "") | 6486 | self.builder.buildZExt(rhs, try self.dg.lowerType(lhs_ty), "") |
| 6487 | else | 6487 | else |
| 6488 | rhs; | 6488 | rhs; |
| 6489 | | 6489 | |
| ... | @@ -6543,7 +6543,7 @@ pub const FuncGen = struct { | ... | @@ -6543,7 +6543,7 @@ pub const FuncGen = struct { |
| 6543 | const tg = self.dg.module.getTarget(); | 6543 | const tg = self.dg.module.getTarget(); |
| 6544 | | 6544 | |
| 6545 | const casted_rhs = if (rhs_scalar_ty.bitSize(tg) < lhs_scalar_ty.bitSize(tg)) | 6545 | const casted_rhs = if (rhs_scalar_ty.bitSize(tg) < lhs_scalar_ty.bitSize(tg)) |
| 6546 | self.builder.buildZExt(rhs, try self.dg.llvmType(lhs_ty), "") | 6546 | self.builder.buildZExt(rhs, try self.dg.lowerType(lhs_ty), "") |
| 6547 | else | 6547 | else |
| 6548 | rhs; | 6548 | rhs; |
| 6549 | if (lhs_scalar_ty.isSignedInt()) return self.builder.buildNSWShl(lhs, casted_rhs, ""); | 6549 | if (lhs_scalar_ty.isSignedInt()) return self.builder.buildNSWShl(lhs, casted_rhs, ""); |
| ... | @@ -6566,7 +6566,7 @@ pub const FuncGen = struct { | ... | @@ -6566,7 +6566,7 @@ pub const FuncGen = struct { |
| 6566 | const tg = self.dg.module.getTarget(); | 6566 | const tg = self.dg.module.getTarget(); |
| 6567 | | 6567 | |
| 6568 | const casted_rhs = if (rhs_scalar_ty.bitSize(tg) < lhs_scalar_ty.bitSize(tg)) | 6568 | const casted_rhs = if (rhs_scalar_ty.bitSize(tg) < lhs_scalar_ty.bitSize(tg)) |
| 6569 | self.builder.buildZExt(rhs, try self.dg.llvmType(lhs_type), "") | 6569 | self.builder.buildZExt(rhs, try self.dg.lowerType(lhs_type), "") |
| 6570 | else | 6570 | else |
| 6571 | rhs; | 6571 | rhs; |
| 6572 | return self.builder.buildShl(lhs, casted_rhs, ""); | 6572 | return self.builder.buildShl(lhs, casted_rhs, ""); |
| ... | @@ -6588,7 +6588,7 @@ pub const FuncGen = struct { | ... | @@ -6588,7 +6588,7 @@ pub const FuncGen = struct { |
| 6588 | const tg = self.dg.module.getTarget(); | 6588 | const tg = self.dg.module.getTarget(); |
| 6589 | | 6589 | |
| 6590 | const casted_rhs = if (rhs_scalar_ty.bitSize(tg) < lhs_scalar_ty.bitSize(tg)) | 6590 | const casted_rhs = if (rhs_scalar_ty.bitSize(tg) < lhs_scalar_ty.bitSize(tg)) |
| 6591 | self.builder.buildZExt(rhs, try self.dg.llvmType(lhs_ty), "") | 6591 | self.builder.buildZExt(rhs, try self.dg.lowerType(lhs_ty), "") |
| 6592 | else | 6592 | else |
| 6593 | rhs; | 6593 | rhs; |
| 6594 | if (lhs_scalar_ty.isSignedInt()) return self.builder.buildSShlSat(lhs, casted_rhs, ""); | 6594 | if (lhs_scalar_ty.isSignedInt()) return self.builder.buildSShlSat(lhs, casted_rhs, ""); |
| ... | @@ -6611,7 +6611,7 @@ pub const FuncGen = struct { | ... | @@ -6611,7 +6611,7 @@ pub const FuncGen = struct { |
| 6611 | const tg = self.dg.module.getTarget(); | 6611 | const tg = self.dg.module.getTarget(); |
| 6612 | | 6612 | |
| 6613 | const casted_rhs = if (rhs_scalar_ty.bitSize(tg) < lhs_scalar_ty.bitSize(tg)) | 6613 | const casted_rhs = if (rhs_scalar_ty.bitSize(tg) < lhs_scalar_ty.bitSize(tg)) |
| 6614 | self.builder.buildZExt(rhs, try self.dg.llvmType(lhs_ty), "") | 6614 | self.builder.buildZExt(rhs, try self.dg.lowerType(lhs_ty), "") |
| 6615 | else | 6615 | else |
| 6616 | rhs; | 6616 | rhs; |
| 6617 | const is_signed_int = lhs_scalar_ty.isSignedInt(); | 6617 | const is_signed_int = lhs_scalar_ty.isSignedInt(); |
| ... | @@ -6639,7 +6639,7 @@ pub const FuncGen = struct { | ... | @@ -6639,7 +6639,7 @@ pub const FuncGen = struct { |
| 6639 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | 6639 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; |
| 6640 | const dest_ty = self.air.typeOfIndex(inst); | 6640 | const dest_ty = self.air.typeOfIndex(inst); |
| 6641 | const dest_info = dest_ty.intInfo(target); | 6641 | const dest_info = dest_ty.intInfo(target); |
| 6642 | const dest_llvm_ty = try self.dg.llvmType(dest_ty); | 6642 | const dest_llvm_ty = try self.dg.lowerType(dest_ty); |
| 6643 | const operand = try self.resolveInst(ty_op.operand); | 6643 | const operand = try self.resolveInst(ty_op.operand); |
| 6644 | const operand_ty = self.air.typeOf(ty_op.operand); | 6644 | const operand_ty = self.air.typeOf(ty_op.operand); |
| 6645 | const operand_info = operand_ty.intInfo(target); | 6645 | const operand_info = operand_ty.intInfo(target); |
| ... | @@ -6661,7 +6661,7 @@ pub const FuncGen = struct { | ... | @@ -6661,7 +6661,7 @@ pub const FuncGen = struct { |
| 6661 | | 6661 | |
| 6662 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | 6662 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; |
| 6663 | const operand = try self.resolveInst(ty_op.operand); | 6663 | const operand = try self.resolveInst(ty_op.operand); |
| 6664 | const dest_llvm_ty = try self.dg.llvmType(self.air.typeOfIndex(inst)); | 6664 | const dest_llvm_ty = try self.dg.lowerType(self.air.typeOfIndex(inst)); |
| 6665 | return self.builder.buildTrunc(operand, dest_llvm_ty, ""); | 6665 | return self.builder.buildTrunc(operand, dest_llvm_ty, ""); |
| 6666 | } | 6666 | } |
| 6667 | | 6667 | |
| ... | @@ -6679,7 +6679,7 @@ pub const FuncGen = struct { | ... | @@ -6679,7 +6679,7 @@ pub const FuncGen = struct { |
| 6679 | if (!backendSupportsF80(target) and (src_bits == 80 or dest_bits == 80)) { | 6679 | if (!backendSupportsF80(target) and (src_bits == 80 or dest_bits == 80)) { |
| 6680 | return softF80TruncOrExt(self, operand, src_bits, dest_bits); | 6680 | return softF80TruncOrExt(self, operand, src_bits, dest_bits); |
| 6681 | } | 6681 | } |
| 6682 | const dest_llvm_ty = try self.dg.llvmType(dest_ty); | 6682 | const dest_llvm_ty = try self.dg.lowerType(dest_ty); |
| 6683 | return self.builder.buildFPTrunc(operand, dest_llvm_ty, ""); | 6683 | return self.builder.buildFPTrunc(operand, dest_llvm_ty, ""); |
| 6684 | } | 6684 | } |
| 6685 | | 6685 | |
| ... | @@ -6697,7 +6697,7 @@ pub const FuncGen = struct { | ... | @@ -6697,7 +6697,7 @@ pub const FuncGen = struct { |
| 6697 | if (!backendSupportsF80(target) and (src_bits == 80 or dest_bits == 80)) { | 6697 | if (!backendSupportsF80(target) and (src_bits == 80 or dest_bits == 80)) { |
| 6698 | return softF80TruncOrExt(self, operand, src_bits, dest_bits); | 6698 | return softF80TruncOrExt(self, operand, src_bits, dest_bits); |
| 6699 | } | 6699 | } |
| 6700 | const dest_llvm_ty = try self.dg.llvmType(self.air.typeOfIndex(inst)); | 6700 | const dest_llvm_ty = try self.dg.lowerType(self.air.typeOfIndex(inst)); |
| 6701 | return self.builder.buildFPExt(operand, dest_llvm_ty, ""); | 6701 | return self.builder.buildFPExt(operand, dest_llvm_ty, ""); |
| 6702 | } | 6702 | } |
| 6703 | | 6703 | |
| ... | @@ -6707,7 +6707,7 @@ pub const FuncGen = struct { | ... | @@ -6707,7 +6707,7 @@ pub const FuncGen = struct { |
| 6707 | | 6707 | |
| 6708 | const un_op = self.air.instructions.items(.data)[inst].un_op; | 6708 | const un_op = self.air.instructions.items(.data)[inst].un_op; |
| 6709 | const operand = try self.resolveInst(un_op); | 6709 | const operand = try self.resolveInst(un_op); |
| 6710 | const dest_llvm_ty = try self.dg.llvmType(self.air.typeOfIndex(inst)); | 6710 | const dest_llvm_ty = try self.dg.lowerType(self.air.typeOfIndex(inst)); |
| 6711 | return self.builder.buildPtrToInt(operand, dest_llvm_ty, ""); | 6711 | return self.builder.buildPtrToInt(operand, dest_llvm_ty, ""); |
| 6712 | } | 6712 | } |
| 6713 | | 6713 | |
| ... | @@ -6720,7 +6720,7 @@ pub const FuncGen = struct { | ... | @@ -6720,7 +6720,7 @@ pub const FuncGen = struct { |
| 6720 | const inst_ty = self.air.typeOfIndex(inst); | 6720 | const inst_ty = self.air.typeOfIndex(inst); |
| 6721 | const operand_is_ref = isByRef(operand_ty); | 6721 | const operand_is_ref = isByRef(operand_ty); |
| 6722 | const result_is_ref = isByRef(inst_ty); | 6722 | const result_is_ref = isByRef(inst_ty); |
| 6723 | const llvm_dest_ty = try self.dg.llvmType(inst_ty); | 6723 | const llvm_dest_ty = try self.dg.lowerType(inst_ty); |
| 6724 | const target = self.dg.module.getTarget(); | 6724 | const target = self.dg.module.getTarget(); |
| 6725 | | 6725 | |
| 6726 | if (operand_is_ref and result_is_ref) { | 6726 | if (operand_is_ref and result_is_ref) { |
| ... | @@ -6740,14 +6740,14 @@ pub const FuncGen = struct { | ... | @@ -6740,14 +6740,14 @@ pub const FuncGen = struct { |
| 6740 | const array_ptr = self.buildAlloca(llvm_dest_ty); | 6740 | const array_ptr = self.buildAlloca(llvm_dest_ty); |
| 6741 | const bitcast_ok = elem_ty.bitSize(target) == elem_ty.abiSize(target) * 8; | 6741 | const bitcast_ok = elem_ty.bitSize(target) == elem_ty.abiSize(target) * 8; |
| 6742 | if (bitcast_ok) { | 6742 | if (bitcast_ok) { |
| 6743 | const llvm_vector_ty = try self.dg.llvmType(operand_ty); | 6743 | const llvm_vector_ty = try self.dg.lowerType(operand_ty); |
| 6744 | const casted_ptr = self.builder.buildBitCast(array_ptr, llvm_vector_ty.pointerType(0), ""); | 6744 | const casted_ptr = self.builder.buildBitCast(array_ptr, llvm_vector_ty.pointerType(0), ""); |
| 6745 | const llvm_store = self.builder.buildStore(operand, casted_ptr); | 6745 | const llvm_store = self.builder.buildStore(operand, casted_ptr); |
| 6746 | llvm_store.setAlignment(inst_ty.abiAlignment(target)); | 6746 | llvm_store.setAlignment(inst_ty.abiAlignment(target)); |
| 6747 | } else { | 6747 | } else { |
| 6748 | // If the ABI size of the element type is not evenly divisible by size in bits; | 6748 | // If the ABI size of the element type is not evenly divisible by size in bits; |
| 6749 | // a simple bitcast will not work, and we fall back to extractelement. | 6749 | // a simple bitcast will not work, and we fall back to extractelement. |
| 6750 | const llvm_usize = try self.dg.llvmType(Type.usize); | 6750 | const llvm_usize = try self.dg.lowerType(Type.usize); |
| 6751 | const llvm_u32 = self.context.intType(32); | 6751 | const llvm_u32 = self.context.intType(32); |
| 6752 | const zero = llvm_usize.constNull(); | 6752 | const zero = llvm_usize.constNull(); |
| 6753 | const vector_len = operand_ty.arrayLen(); | 6753 | const vector_len = operand_ty.arrayLen(); |
| ... | @@ -6764,7 +6764,7 @@ pub const FuncGen = struct { | ... | @@ -6764,7 +6764,7 @@ pub const FuncGen = struct { |
| 6764 | return array_ptr; | 6764 | return array_ptr; |
| 6765 | } else if (operand_ty.zigTypeTag() == .Array and inst_ty.zigTypeTag() == .Vector) { | 6765 | } else if (operand_ty.zigTypeTag() == .Array and inst_ty.zigTypeTag() == .Vector) { |
| 6766 | const elem_ty = operand_ty.childType(); | 6766 | const elem_ty = operand_ty.childType(); |
| 6767 | const llvm_vector_ty = try self.dg.llvmType(inst_ty); | 6767 | const llvm_vector_ty = try self.dg.lowerType(inst_ty); |
| 6768 | if (!operand_is_ref) { | 6768 | if (!operand_is_ref) { |
| 6769 | return self.dg.todo("implement bitcast non-ref array to vector", .{}); | 6769 | return self.dg.todo("implement bitcast non-ref array to vector", .{}); |
| 6770 | } | 6770 | } |
| ... | @@ -6781,7 +6781,7 @@ pub const FuncGen = struct { | ... | @@ -6781,7 +6781,7 @@ pub const FuncGen = struct { |
| 6781 | } else { | 6781 | } else { |
| 6782 | // If the ABI size of the element type is not evenly divisible by size in bits; | 6782 | // If the ABI size of the element type is not evenly divisible by size in bits; |
| 6783 | // a simple bitcast will not work, and we fall back to extractelement. | 6783 | // a simple bitcast will not work, and we fall back to extractelement. |
| 6784 | const llvm_usize = try self.dg.llvmType(Type.usize); | 6784 | const llvm_usize = try self.dg.lowerType(Type.usize); |
| 6785 | const llvm_u32 = self.context.intType(32); | 6785 | const llvm_u32 = self.context.intType(32); |
| 6786 | const zero = llvm_usize.constNull(); | 6786 | const zero = llvm_usize.constNull(); |
| 6787 | const vector_len = operand_ty.arrayLen(); | 6787 | const vector_len = operand_ty.arrayLen(); |
| ... | @@ -6813,7 +6813,7 @@ pub const FuncGen = struct { | ... | @@ -6813,7 +6813,7 @@ pub const FuncGen = struct { |
| 6813 | const alignment = @maximum(operand_ty.abiAlignment(target), inst_ty.abiAlignment(target)); | 6813 | const alignment = @maximum(operand_ty.abiAlignment(target), inst_ty.abiAlignment(target)); |
| 6814 | const result_ptr = self.buildAlloca(llvm_dest_ty); | 6814 | const result_ptr = self.buildAlloca(llvm_dest_ty); |
| 6815 | result_ptr.setAlignment(alignment); | 6815 | result_ptr.setAlignment(alignment); |
| 6816 | const operand_llvm_ty = try self.dg.llvmType(operand_ty); | 6816 | const operand_llvm_ty = try self.dg.lowerType(operand_ty); |
| 6817 | const casted_ptr = self.builder.buildBitCast(result_ptr, operand_llvm_ty.pointerType(0), ""); | 6817 | const casted_ptr = self.builder.buildBitCast(result_ptr, operand_llvm_ty.pointerType(0), ""); |
| 6818 | const store_inst = self.builder.buildStore(operand, casted_ptr); | 6818 | const store_inst = self.builder.buildStore(operand, casted_ptr); |
| 6819 | store_inst.setAlignment(alignment); | 6819 | store_inst.setAlignment(alignment); |
| ... | @@ -6827,7 +6827,7 @@ pub const FuncGen = struct { | ... | @@ -6827,7 +6827,7 @@ pub const FuncGen = struct { |
| 6827 | const alignment = @maximum(operand_ty.abiAlignment(target), inst_ty.abiAlignment(target)); | 6827 | const alignment = @maximum(operand_ty.abiAlignment(target), inst_ty.abiAlignment(target)); |
| 6828 | const result_ptr = self.buildAlloca(llvm_dest_ty); | 6828 | const result_ptr = self.buildAlloca(llvm_dest_ty); |
| 6829 | result_ptr.setAlignment(alignment); | 6829 | result_ptr.setAlignment(alignment); |
| 6830 | const operand_llvm_ty = try self.dg.llvmType(operand_ty); | 6830 | const operand_llvm_ty = try self.dg.lowerType(operand_ty); |
| 6831 | const casted_ptr = self.builder.buildBitCast(result_ptr, operand_llvm_ty.pointerType(0), ""); | 6831 | const casted_ptr = self.builder.buildBitCast(result_ptr, operand_llvm_ty.pointerType(0), ""); |
| 6832 | const store_inst = self.builder.buildStore(operand, casted_ptr); | 6832 | const store_inst = self.builder.buildStore(operand, casted_ptr); |
| 6833 | store_inst.setAlignment(alignment); | 6833 | store_inst.setAlignment(alignment); |
| ... | @@ -6901,7 +6901,7 @@ pub const FuncGen = struct { | ... | @@ -6901,7 +6901,7 @@ pub const FuncGen = struct { |
| 6901 | const pointee_type = ptr_ty.childType(); | 6901 | const pointee_type = ptr_ty.childType(); |
| 6902 | if (!pointee_type.isFnOrHasRuntimeBitsIgnoreComptime()) return self.dg.lowerPtrToVoid(ptr_ty); | 6902 | if (!pointee_type.isFnOrHasRuntimeBitsIgnoreComptime()) return self.dg.lowerPtrToVoid(ptr_ty); |
| 6903 | | 6903 | |
| 6904 | const pointee_llvm_ty = try self.dg.llvmType(pointee_type); | 6904 | const pointee_llvm_ty = try self.dg.lowerType(pointee_type); |
| 6905 | const alloca_inst = self.buildAlloca(pointee_llvm_ty); | 6905 | const alloca_inst = self.buildAlloca(pointee_llvm_ty); |
| 6906 | const target = self.dg.module.getTarget(); | 6906 | const target = self.dg.module.getTarget(); |
| 6907 | const alignment = ptr_ty.ptrAlignment(target); | 6907 | const alignment = ptr_ty.ptrAlignment(target); |
| ... | @@ -6915,7 +6915,7 @@ pub const FuncGen = struct { | ... | @@ -6915,7 +6915,7 @@ pub const FuncGen = struct { |
| 6915 | const ret_ty = ptr_ty.childType(); | 6915 | const ret_ty = ptr_ty.childType(); |
| 6916 | if (!ret_ty.isFnOrHasRuntimeBitsIgnoreComptime()) return self.dg.lowerPtrToVoid(ptr_ty); | 6916 | if (!ret_ty.isFnOrHasRuntimeBitsIgnoreComptime()) return self.dg.lowerPtrToVoid(ptr_ty); |
| 6917 | if (self.ret_ptr) |ret_ptr| return ret_ptr; | 6917 | if (self.ret_ptr) |ret_ptr| return ret_ptr; |
| 6918 | const ret_llvm_ty = try self.dg.llvmType(ret_ty); | 6918 | const ret_llvm_ty = try self.dg.lowerType(ret_ty); |
| 6919 | const target = self.dg.module.getTarget(); | 6919 | const target = self.dg.module.getTarget(); |
| 6920 | const alloca_inst = self.buildAlloca(ret_llvm_ty); | 6920 | const alloca_inst = self.buildAlloca(ret_llvm_ty); |
| 6921 | alloca_inst.setAlignment(ptr_ty.ptrAlignment(target)); | 6921 | alloca_inst.setAlignment(ptr_ty.ptrAlignment(target)); |
| ... | @@ -6946,7 +6946,7 @@ pub const FuncGen = struct { | ... | @@ -6946,7 +6946,7 @@ pub const FuncGen = struct { |
| 6946 | const dest_ptr_u8 = self.builder.buildBitCast(dest_ptr, ptr_u8_llvm_ty, ""); | 6946 | const dest_ptr_u8 = self.builder.buildBitCast(dest_ptr, ptr_u8_llvm_ty, ""); |
| 6947 | const fill_char = u8_llvm_ty.constInt(0xaa, .False); | 6947 | const fill_char = u8_llvm_ty.constInt(0xaa, .False); |
| 6948 | const dest_ptr_align = ptr_ty.ptrAlignment(target); | 6948 | const dest_ptr_align = ptr_ty.ptrAlignment(target); |
| 6949 | const usize_llvm_ty = try self.dg.llvmType(Type.usize); | 6949 | const usize_llvm_ty = try self.dg.lowerType(Type.usize); |
| 6950 | const len = usize_llvm_ty.constInt(operand_size, .False); | 6950 | const len = usize_llvm_ty.constInt(operand_size, .False); |
| 6951 | _ = self.builder.buildMemSet(dest_ptr_u8, fill_char, len, dest_ptr_align, ptr_ty.isVolatilePtr()); | 6951 | _ = self.builder.buildMemSet(dest_ptr_u8, fill_char, len, dest_ptr_align, ptr_ty.isVolatilePtr()); |
| 6952 | if (self.dg.module.comp.bin_file.options.valgrind) { | 6952 | if (self.dg.module.comp.bin_file.options.valgrind) { |
| ... | @@ -6983,7 +6983,7 @@ pub const FuncGen = struct { | ... | @@ -6983,7 +6983,7 @@ pub const FuncGen = struct { |
| 6983 | const llvm_fn = self.getIntrinsic("llvm.returnaddress", &.{}); | 6983 | const llvm_fn = self.getIntrinsic("llvm.returnaddress", &.{}); |
| 6984 | const params = [_]*const llvm.Value{llvm_i32.constNull()}; | 6984 | const params = [_]*const llvm.Value{llvm_i32.constNull()}; |
| 6985 | const ptr_val = self.builder.buildCall(llvm_fn, &params, params.len, .Fast, .Auto, ""); | 6985 | const ptr_val = self.builder.buildCall(llvm_fn, &params, params.len, .Fast, .Auto, ""); |
| 6986 | const llvm_usize = try self.dg.llvmType(Type.usize); | 6986 | const llvm_usize = try self.dg.lowerType(Type.usize); |
| 6987 | return self.builder.buildPtrToInt(ptr_val, llvm_usize, ""); | 6987 | return self.builder.buildPtrToInt(ptr_val, llvm_usize, ""); |
| 6988 | } | 6988 | } |
| 6989 | | 6989 | |
| ... | @@ -7001,7 +7001,7 @@ pub const FuncGen = struct { | ... | @@ -7001,7 +7001,7 @@ pub const FuncGen = struct { |
| 7001 | | 7001 | |
| 7002 | const params = [_]*const llvm.Value{llvm_i32.constNull()}; | 7002 | const params = [_]*const llvm.Value{llvm_i32.constNull()}; |
| 7003 | const ptr_val = self.builder.buildCall(llvm_fn, &params, params.len, .Fast, .Auto, ""); | 7003 | const ptr_val = self.builder.buildCall(llvm_fn, &params, params.len, .Fast, .Auto, ""); |
| 7004 | const llvm_usize = try self.dg.llvmType(Type.usize); | 7004 | const llvm_usize = try self.dg.lowerType(Type.usize); |
| 7005 | return self.builder.buildPtrToInt(ptr_val, llvm_usize, ""); | 7005 | return self.builder.buildPtrToInt(ptr_val, llvm_usize, ""); |
| 7006 | } | 7006 | } |
| 7007 | | 7007 | |
| ... | @@ -7046,7 +7046,7 @@ pub const FuncGen = struct { | ... | @@ -7046,7 +7046,7 @@ pub const FuncGen = struct { |
| 7046 | | 7046 | |
| 7047 | var payload = self.builder.buildExtractValue(result, 0, ""); | 7047 | var payload = self.builder.buildExtractValue(result, 0, ""); |
| 7048 | if (opt_abi_ty != null) { | 7048 | if (opt_abi_ty != null) { |
| 7049 | payload = self.builder.buildTrunc(payload, try self.dg.llvmType(operand_ty), ""); | 7049 | payload = self.builder.buildTrunc(payload, try self.dg.lowerType(operand_ty), ""); |
| 7050 | } | 7050 | } |
| 7051 | const success_bit = self.builder.buildExtractValue(result, 1, ""); | 7051 | const success_bit = self.builder.buildExtractValue(result, 1, ""); |
| 7052 | | 7052 | |
| ... | @@ -7054,7 +7054,7 @@ pub const FuncGen = struct { | ... | @@ -7054,7 +7054,7 @@ pub const FuncGen = struct { |
| 7054 | return self.builder.buildSelect(success_bit, payload.typeOf().constNull(), payload, ""); | 7054 | return self.builder.buildSelect(success_bit, payload.typeOf().constNull(), payload, ""); |
| 7055 | } | 7055 | } |
| 7056 | | 7056 | |
| 7057 | const optional_llvm_ty = try self.dg.llvmType(optional_ty); | 7057 | const optional_llvm_ty = try self.dg.lowerType(optional_ty); |
| 7058 | const non_null_bit = self.builder.buildNot(success_bit, ""); | 7058 | const non_null_bit = self.builder.buildNot(success_bit, ""); |
| 7059 | const partial = self.builder.buildInsertValue(optional_llvm_ty.getUndef(), payload, 0, ""); | 7059 | const partial = self.builder.buildInsertValue(optional_llvm_ty.getUndef(), payload, 0, ""); |
| 7060 | return self.builder.buildInsertValue(partial, non_null_bit, 1, ""); | 7060 | return self.builder.buildInsertValue(partial, non_null_bit, 1, ""); |
| ... | @@ -7090,7 +7090,7 @@ pub const FuncGen = struct { | ... | @@ -7090,7 +7090,7 @@ pub const FuncGen = struct { |
| 7090 | ordering, | 7090 | ordering, |
| 7091 | single_threaded, | 7091 | single_threaded, |
| 7092 | ); | 7092 | ); |
| 7093 | const operand_llvm_ty = try self.dg.llvmType(operand_ty); | 7093 | const operand_llvm_ty = try self.dg.lowerType(operand_ty); |
| 7094 | if (is_float) { | 7094 | if (is_float) { |
| 7095 | return self.builder.buildBitCast(uncasted_result, operand_llvm_ty, ""); | 7095 | return self.builder.buildBitCast(uncasted_result, operand_llvm_ty, ""); |
| 7096 | } else { | 7096 | } else { |
| ... | @@ -7103,7 +7103,7 @@ pub const FuncGen = struct { | ... | @@ -7103,7 +7103,7 @@ pub const FuncGen = struct { |
| 7103 | } | 7103 | } |
| 7104 | | 7104 | |
| 7105 | // It's a pointer but we need to treat it as an int. | 7105 | // It's a pointer but we need to treat it as an int. |
| 7106 | const usize_llvm_ty = try self.dg.llvmType(Type.usize); | 7106 | const usize_llvm_ty = try self.dg.lowerType(Type.usize); |
| 7107 | const casted_ptr = self.builder.buildBitCast(ptr, usize_llvm_ty.pointerType(0), ""); | 7107 | const casted_ptr = self.builder.buildBitCast(ptr, usize_llvm_ty.pointerType(0), ""); |
| 7108 | const casted_operand = self.builder.buildPtrToInt(operand, usize_llvm_ty, ""); | 7108 | const casted_operand = self.builder.buildPtrToInt(operand, usize_llvm_ty, ""); |
| 7109 | const uncasted_result = self.builder.buildAtomicRmw( | 7109 | const uncasted_result = self.builder.buildAtomicRmw( |
| ... | @@ -7113,7 +7113,7 @@ pub const FuncGen = struct { | ... | @@ -7113,7 +7113,7 @@ pub const FuncGen = struct { |
| 7113 | ordering, | 7113 | ordering, |
| 7114 | single_threaded, | 7114 | single_threaded, |
| 7115 | ); | 7115 | ); |
| 7116 | const operand_llvm_ty = try self.dg.llvmType(operand_ty); | 7116 | const operand_llvm_ty = try self.dg.lowerType(operand_ty); |
| 7117 | return self.builder.buildIntToPtr(uncasted_result, operand_llvm_ty, ""); | 7117 | return self.builder.buildIntToPtr(uncasted_result, operand_llvm_ty, ""); |
| 7118 | } | 7118 | } |
| 7119 | | 7119 | |
| ... | @@ -7132,7 +7132,7 @@ pub const FuncGen = struct { | ... | @@ -7132,7 +7132,7 @@ pub const FuncGen = struct { |
| 7132 | const casted_ptr = self.builder.buildBitCast(ptr, abi_ty.pointerType(0), ""); | 7132 | const casted_ptr = self.builder.buildBitCast(ptr, abi_ty.pointerType(0), ""); |
| 7133 | const load_inst = (try self.load(casted_ptr, ptr_ty)).?; | 7133 | const load_inst = (try self.load(casted_ptr, ptr_ty)).?; |
| 7134 | load_inst.setOrdering(ordering); | 7134 | load_inst.setOrdering(ordering); |
| 7135 | return self.builder.buildTrunc(load_inst, try self.dg.llvmType(operand_ty), ""); | 7135 | return self.builder.buildTrunc(load_inst, try self.dg.lowerType(operand_ty), ""); |
| 7136 | } | 7136 | } |
| 7137 | const load_inst = (try self.load(ptr, ptr_ty)).?; | 7137 | const load_inst = (try self.load(ptr, ptr_ty)).?; |
| 7138 | load_inst.setOrdering(ordering); | 7138 | load_inst.setOrdering(ordering); |
| ... | @@ -7273,13 +7273,13 @@ pub const FuncGen = struct { | ... | @@ -7273,13 +7273,13 @@ pub const FuncGen = struct { |
| 7273 | const operand = try self.resolveInst(ty_op.operand); | 7273 | const operand = try self.resolveInst(ty_op.operand); |
| 7274 | | 7274 | |
| 7275 | const llvm_i1 = self.context.intType(1); | 7275 | const llvm_i1 = self.context.intType(1); |
| 7276 | const operand_llvm_ty = try self.dg.llvmType(operand_ty); | 7276 | const operand_llvm_ty = try self.dg.lowerType(operand_ty); |
| 7277 | const fn_val = self.getIntrinsic(llvm_fn_name, &.{operand_llvm_ty}); | 7277 | const fn_val = self.getIntrinsic(llvm_fn_name, &.{operand_llvm_ty}); |
| 7278 | | 7278 | |
| 7279 | const params = [_]*const llvm.Value{ operand, llvm_i1.constNull() }; | 7279 | const params = [_]*const llvm.Value{ operand, llvm_i1.constNull() }; |
| 7280 | const wrong_size_result = self.builder.buildCall(fn_val, &params, params.len, .C, .Auto, ""); | 7280 | const wrong_size_result = self.builder.buildCall(fn_val, &params, params.len, .C, .Auto, ""); |
| 7281 | const result_ty = self.air.typeOfIndex(inst); | 7281 | const result_ty = self.air.typeOfIndex(inst); |
| 7282 | const result_llvm_ty = try self.dg.llvmType(result_ty); | 7282 | const result_llvm_ty = try self.dg.lowerType(result_ty); |
| 7283 | | 7283 | |
| 7284 | const target = self.dg.module.getTarget(); | 7284 | const target = self.dg.module.getTarget(); |
| 7285 | const bits = operand_ty.intInfo(target).bits; | 7285 | const bits = operand_ty.intInfo(target).bits; |
| ... | @@ -7301,12 +7301,12 @@ pub const FuncGen = struct { | ... | @@ -7301,12 +7301,12 @@ pub const FuncGen = struct { |
| 7301 | const operand = try self.resolveInst(ty_op.operand); | 7301 | const operand = try self.resolveInst(ty_op.operand); |
| 7302 | | 7302 | |
| 7303 | const params = [_]*const llvm.Value{operand}; | 7303 | const params = [_]*const llvm.Value{operand}; |
| 7304 | const operand_llvm_ty = try self.dg.llvmType(operand_ty); | 7304 | const operand_llvm_ty = try self.dg.lowerType(operand_ty); |
| 7305 | const fn_val = self.getIntrinsic(llvm_fn_name, &.{operand_llvm_ty}); | 7305 | const fn_val = self.getIntrinsic(llvm_fn_name, &.{operand_llvm_ty}); |
| 7306 | | 7306 | |
| 7307 | const wrong_size_result = self.builder.buildCall(fn_val, &params, params.len, .C, .Auto, ""); | 7307 | const wrong_size_result = self.builder.buildCall(fn_val, &params, params.len, .C, .Auto, ""); |
| 7308 | const result_ty = self.air.typeOfIndex(inst); | 7308 | const result_ty = self.air.typeOfIndex(inst); |
| 7309 | const result_llvm_ty = try self.dg.llvmType(result_ty); | 7309 | const result_llvm_ty = try self.dg.lowerType(result_ty); |
| 7310 | | 7310 | |
| 7311 | const target = self.dg.module.getTarget(); | 7311 | const target = self.dg.module.getTarget(); |
| 7312 | const bits = operand_ty.intInfo(target).bits; | 7312 | const bits = operand_ty.intInfo(target).bits; |
| ... | @@ -7330,7 +7330,7 @@ pub const FuncGen = struct { | ... | @@ -7330,7 +7330,7 @@ pub const FuncGen = struct { |
| 7330 | assert(bits % 8 == 0); | 7330 | assert(bits % 8 == 0); |
| 7331 | | 7331 | |
| 7332 | var operand = try self.resolveInst(ty_op.operand); | 7332 | var operand = try self.resolveInst(ty_op.operand); |
| 7333 | var operand_llvm_ty = try self.dg.llvmType(operand_ty); | 7333 | var operand_llvm_ty = try self.dg.lowerType(operand_ty); |
| 7334 | | 7334 | |
| 7335 | if (bits % 16 == 8) { | 7335 | if (bits % 16 == 8) { |
| 7336 | // If not an even byte-multiple, we need zero-extend + shift-left 1 byte | 7336 | // If not an even byte-multiple, we need zero-extend + shift-left 1 byte |
| ... | @@ -7364,7 +7364,7 @@ pub const FuncGen = struct { | ... | @@ -7364,7 +7364,7 @@ pub const FuncGen = struct { |
| 7364 | const wrong_size_result = self.builder.buildCall(fn_val, &params, params.len, .C, .Auto, ""); | 7364 | const wrong_size_result = self.builder.buildCall(fn_val, &params, params.len, .C, .Auto, ""); |
| 7365 | | 7365 | |
| 7366 | const result_ty = self.air.typeOfIndex(inst); | 7366 | const result_ty = self.air.typeOfIndex(inst); |
| 7367 | const result_llvm_ty = try self.dg.llvmType(result_ty); | 7367 | const result_llvm_ty = try self.dg.lowerType(result_ty); |
| 7368 | const result_bits = result_ty.intInfo(target).bits; | 7368 | const result_bits = result_ty.intInfo(target).bits; |
| 7369 | if (bits > result_bits) { | 7369 | if (bits > result_bits) { |
| 7370 | return self.builder.buildTrunc(wrong_size_result, result_llvm_ty, ""); | 7370 | return self.builder.buildTrunc(wrong_size_result, result_llvm_ty, ""); |
| ... | @@ -7407,14 +7407,14 @@ pub const FuncGen = struct { | ... | @@ -7407,14 +7407,14 @@ pub const FuncGen = struct { |
| 7407 | } | 7407 | } |
| 7408 | | 7408 | |
| 7409 | const slice_ty = Type.initTag(.const_slice_u8_sentinel_0); | 7409 | const slice_ty = Type.initTag(.const_slice_u8_sentinel_0); |
| 7410 | const llvm_ret_ty = try self.dg.llvmType(slice_ty); | 7410 | const llvm_ret_ty = try self.dg.lowerType(slice_ty); |
| 7411 | const usize_llvm_ty = try self.dg.llvmType(Type.usize); | 7411 | const usize_llvm_ty = try self.dg.lowerType(Type.usize); |
| 7412 | const target = self.dg.module.getTarget(); | 7412 | const target = self.dg.module.getTarget(); |
| 7413 | const slice_alignment = slice_ty.abiAlignment(target); | 7413 | const slice_alignment = slice_ty.abiAlignment(target); |
| 7414 | | 7414 | |
| 7415 | var int_tag_type_buffer: Type.Payload.Bits = undefined; | 7415 | var int_tag_type_buffer: Type.Payload.Bits = undefined; |
| 7416 | const int_tag_ty = enum_ty.intTagType(&int_tag_type_buffer); | 7416 | const int_tag_ty = enum_ty.intTagType(&int_tag_type_buffer); |
| 7417 | const param_types = [_]*const llvm.Type{try self.dg.llvmType(int_tag_ty)}; | 7417 | const param_types = [_]*const llvm.Type{try self.dg.lowerType(int_tag_ty)}; |
| 7418 | | 7418 | |
| 7419 | const fn_type = llvm.functionType(llvm_ret_ty, &param_types, param_types.len, .False); | 7419 | const fn_type = llvm.functionType(llvm_ret_ty, &param_types, param_types.len, .False); |
| 7420 | const fn_val = self.dg.object.llvm_module.addFunction(llvm_fn_name, fn_type); | 7420 | const fn_val = self.dg.object.llvm_module.addFunction(llvm_fn_name, fn_type); |
| ... | @@ -7471,7 +7471,7 @@ pub const FuncGen = struct { | ... | @@ -7471,7 +7471,7 @@ pub const FuncGen = struct { |
| 7471 | .base = .{ .tag = .enum_field_index }, | 7471 | .base = .{ .tag = .enum_field_index }, |
| 7472 | .data = @intCast(u32, field_index), | 7472 | .data = @intCast(u32, field_index), |
| 7473 | }; | 7473 | }; |
| 7474 | break :int try self.dg.genTypedValue(.{ | 7474 | break :int try self.dg.lowerValue(.{ |
| 7475 | .ty = enum_ty, | 7475 | .ty = enum_ty, |
| 7476 | .val = Value.initPayload(&tag_val_payload.base), | 7476 | .val = Value.initPayload(&tag_val_payload.base), |
| 7477 | }); | 7477 | }); |
| ... | @@ -7496,8 +7496,8 @@ pub const FuncGen = struct { | ... | @@ -7496,8 +7496,8 @@ pub const FuncGen = struct { |
| 7496 | | 7496 | |
| 7497 | // Function signature: fn (anyerror) bool | 7497 | // Function signature: fn (anyerror) bool |
| 7498 | | 7498 | |
| 7499 | const ret_llvm_ty = try self.dg.llvmType(Type.bool); | 7499 | const ret_llvm_ty = try self.dg.lowerType(Type.bool); |
| 7500 | const anyerror_llvm_ty = try self.dg.llvmType(Type.anyerror); | 7500 | const anyerror_llvm_ty = try self.dg.lowerType(Type.anyerror); |
| 7501 | const param_types = [_]*const llvm.Type{anyerror_llvm_ty}; | 7501 | const param_types = [_]*const llvm.Type{anyerror_llvm_ty}; |
| 7502 | | 7502 | |
| 7503 | const fn_type = llvm.functionType(ret_llvm_ty, &param_types, param_types.len, .False); | 7503 | const fn_type = llvm.functionType(ret_llvm_ty, &param_types, param_types.len, .False); |
| ... | @@ -7606,7 +7606,7 @@ pub const FuncGen = struct { | ... | @@ -7606,7 +7606,7 @@ pub const FuncGen = struct { |
| 7606 | .Add => switch (scalar_ty.zigTypeTag()) { | 7606 | .Add => switch (scalar_ty.zigTypeTag()) { |
| 7607 | .Int => return self.builder.buildAddReduce(operand), | 7607 | .Int => return self.builder.buildAddReduce(operand), |
| 7608 | .Float => { | 7608 | .Float => { |
| 7609 | const scalar_llvm_ty = try self.dg.llvmType(scalar_ty); | 7609 | const scalar_llvm_ty = try self.dg.lowerType(scalar_ty); |
| 7610 | const neutral_value = scalar_llvm_ty.constReal(-0.0); | 7610 | const neutral_value = scalar_llvm_ty.constReal(-0.0); |
| 7611 | return self.builder.buildFPAddReduce(neutral_value, operand); | 7611 | return self.builder.buildFPAddReduce(neutral_value, operand); |
| 7612 | }, | 7612 | }, |
| ... | @@ -7615,7 +7615,7 @@ pub const FuncGen = struct { | ... | @@ -7615,7 +7615,7 @@ pub const FuncGen = struct { |
| 7615 | .Mul => switch (scalar_ty.zigTypeTag()) { | 7615 | .Mul => switch (scalar_ty.zigTypeTag()) { |
| 7616 | .Int => return self.builder.buildMulReduce(operand), | 7616 | .Int => return self.builder.buildMulReduce(operand), |
| 7617 | .Float => { | 7617 | .Float => { |
| 7618 | const scalar_llvm_ty = try self.dg.llvmType(scalar_ty); | 7618 | const scalar_llvm_ty = try self.dg.lowerType(scalar_ty); |
| 7619 | const neutral_value = scalar_llvm_ty.constReal(1.0); | 7619 | const neutral_value = scalar_llvm_ty.constReal(1.0); |
| 7620 | return self.builder.buildFPMulReduce(neutral_value, operand); | 7620 | return self.builder.buildFPMulReduce(neutral_value, operand); |
| 7621 | }, | 7621 | }, |
| ... | @@ -7631,7 +7631,7 @@ pub const FuncGen = struct { | ... | @@ -7631,7 +7631,7 @@ pub const FuncGen = struct { |
| 7631 | const result_ty = self.air.typeOfIndex(inst); | 7631 | const result_ty = self.air.typeOfIndex(inst); |
| 7632 | const len = @intCast(usize, result_ty.arrayLen()); | 7632 | const len = @intCast(usize, result_ty.arrayLen()); |
| 7633 | const elements = @ptrCast([]const Air.Inst.Ref, self.air.extra[ty_pl.payload..][0..len]); | 7633 | const elements = @ptrCast([]const Air.Inst.Ref, self.air.extra[ty_pl.payload..][0..len]); |
| 7634 | const llvm_result_ty = try self.dg.llvmType(result_ty); | 7634 | const llvm_result_ty = try self.dg.lowerType(result_ty); |
| 7635 | const target = self.dg.module.getTarget(); | 7635 | const target = self.dg.module.getTarget(); |
| 7636 | | 7636 | |
| 7637 | switch (result_ty.zigTypeTag()) { | 7637 | switch (result_ty.zigTypeTag()) { |
| ... | @@ -7719,7 +7719,7 @@ pub const FuncGen = struct { | ... | @@ -7719,7 +7719,7 @@ pub const FuncGen = struct { |
| 7719 | .Array => { | 7719 | .Array => { |
| 7720 | assert(isByRef(result_ty)); | 7720 | assert(isByRef(result_ty)); |
| 7721 | | 7721 | |
| 7722 | const llvm_usize = try self.dg.llvmType(Type.usize); | 7722 | const llvm_usize = try self.dg.lowerType(Type.usize); |
| 7723 | const alloca_inst = self.buildAlloca(llvm_result_ty); | 7723 | const alloca_inst = self.buildAlloca(llvm_result_ty); |
| 7724 | alloca_inst.setAlignment(result_ty.abiAlignment(target)); | 7724 | alloca_inst.setAlignment(result_ty.abiAlignment(target)); |
| 7725 | | 7725 | |
| ... | @@ -7754,7 +7754,7 @@ pub const FuncGen = struct { | ... | @@ -7754,7 +7754,7 @@ pub const FuncGen = struct { |
| 7754 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | 7754 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; |
| 7755 | const extra = self.air.extraData(Air.UnionInit, ty_pl.payload).data; | 7755 | const extra = self.air.extraData(Air.UnionInit, ty_pl.payload).data; |
| 7756 | const union_ty = self.air.typeOfIndex(inst); | 7756 | const union_ty = self.air.typeOfIndex(inst); |
| 7757 | const union_llvm_ty = try self.dg.llvmType(union_ty); | 7757 | const union_llvm_ty = try self.dg.lowerType(union_ty); |
| 7758 | const target = self.dg.module.getTarget(); | 7758 | const target = self.dg.module.getTarget(); |
| 7759 | const layout = union_ty.unionGetLayout(target); | 7759 | const layout = union_ty.unionGetLayout(target); |
| 7760 | if (layout.payload_size == 0) { | 7760 | if (layout.payload_size == 0) { |
| ... | @@ -7774,8 +7774,8 @@ pub const FuncGen = struct { | ... | @@ -7774,8 +7774,8 @@ pub const FuncGen = struct { |
| 7774 | const union_obj = union_ty.cast(Type.Payload.Union).?.data; | 7774 | const union_obj = union_ty.cast(Type.Payload.Union).?.data; |
| 7775 | assert(union_obj.haveFieldTypes()); | 7775 | assert(union_obj.haveFieldTypes()); |
| 7776 | const field = union_obj.fields.values()[extra.field_index]; | 7776 | const field = union_obj.fields.values()[extra.field_index]; |
| 7777 | const field_llvm_ty = try self.dg.llvmType(field.ty); | 7777 | const field_llvm_ty = try self.dg.lowerType(field.ty); |
| 7778 | const tag_llvm_ty = try self.dg.llvmType(union_obj.tag_ty); | 7778 | const tag_llvm_ty = try self.dg.lowerType(union_obj.tag_ty); |
| 7779 | const field_size = field.ty.abiSize(target); | 7779 | const field_size = field.ty.abiSize(target); |
| 7780 | const field_align = field.normalAlignment(target); | 7780 | const field_align = field.normalAlignment(target); |
| 7781 | | 7781 | |
| ... | @@ -8011,7 +8011,7 @@ pub const FuncGen = struct { | ... | @@ -8011,7 +8011,7 @@ pub const FuncGen = struct { |
| 8011 | | 8011 | |
| 8012 | const slice_ty = Type.initTag(.const_slice_u8_sentinel_0); | 8012 | const slice_ty = Type.initTag(.const_slice_u8_sentinel_0); |
| 8013 | const slice_alignment = slice_ty.abiAlignment(self.dg.module.getTarget()); | 8013 | const slice_alignment = slice_ty.abiAlignment(self.dg.module.getTarget()); |
| 8014 | const llvm_slice_ty = try self.dg.llvmType(slice_ty); | 8014 | const llvm_slice_ty = try self.dg.lowerType(slice_ty); |
| 8015 | const llvm_slice_ptr_ty = llvm_slice_ty.pointerType(0); // TODO: Address space | 8015 | const llvm_slice_ptr_ty = llvm_slice_ty.pointerType(0); // TODO: Address space |
| 8016 | | 8016 | |
| 8017 | const error_name_table_global = self.dg.object.llvm_module.addGlobal(llvm_slice_ptr_ty, "__zig_err_name_table"); | 8017 | const error_name_table_global = self.dg.object.llvm_module.addGlobal(llvm_slice_ptr_ty, "__zig_err_name_table"); |
| ... | @@ -8075,7 +8075,7 @@ pub const FuncGen = struct { | ... | @@ -8075,7 +8075,7 @@ pub const FuncGen = struct { |
| 8075 | // out the relevant bits when accessing the pointee. | 8075 | // out the relevant bits when accessing the pointee. |
| 8076 | // Here we perform a bitcast because we want to use the host_size | 8076 | // Here we perform a bitcast because we want to use the host_size |
| 8077 | // as the llvm pointer element type. | 8077 | // as the llvm pointer element type. |
| 8078 | const result_llvm_ty = try self.dg.llvmType(self.air.typeOfIndex(inst)); | 8078 | const result_llvm_ty = try self.dg.lowerType(self.air.typeOfIndex(inst)); |
| 8079 | // TODO this can be removed if we change host_size to be bits instead | 8079 | // TODO this can be removed if we change host_size to be bits instead |
| 8080 | // of bytes. | 8080 | // of bytes. |
| 8081 | return self.builder.buildBitCast(struct_ptr, result_llvm_ty, ""); | 8081 | return self.builder.buildBitCast(struct_ptr, result_llvm_ty, ""); |
| ... | @@ -8090,7 +8090,7 @@ pub const FuncGen = struct { | ... | @@ -8090,7 +8090,7 @@ pub const FuncGen = struct { |
| 8090 | // end of the struct. Treat our struct pointer as an array of two and get | 8090 | // end of the struct. Treat our struct pointer as an array of two and get |
| 8091 | // the index to the element at index `1` to get a pointer to the end of | 8091 | // the index to the element at index `1` to get a pointer to the end of |
| 8092 | // the struct. | 8092 | // the struct. |
| 8093 | const llvm_usize = try self.dg.llvmType(Type.usize); | 8093 | const llvm_usize = try self.dg.lowerType(Type.usize); |
| 8094 | const llvm_index = llvm_usize.constInt(1, .False); | 8094 | const llvm_index = llvm_usize.constInt(1, .False); |
| 8095 | const indices: [1]*const llvm.Value = .{llvm_index}; | 8095 | const indices: [1]*const llvm.Value = .{llvm_index}; |
| 8096 | return self.builder.buildInBoundsGEP(struct_ptr, &indices, indices.len, ""); | 8096 | return self.builder.buildInBoundsGEP(struct_ptr, &indices, indices.len, ""); |
| ... | @@ -8111,7 +8111,7 @@ pub const FuncGen = struct { | ... | @@ -8111,7 +8111,7 @@ pub const FuncGen = struct { |
| 8111 | ) !?*const llvm.Value { | 8111 | ) !?*const llvm.Value { |
| 8112 | const union_obj = union_ty.cast(Type.Payload.Union).?.data; | 8112 | const union_obj = union_ty.cast(Type.Payload.Union).?.data; |
| 8113 | const field = &union_obj.fields.values()[field_index]; | 8113 | const field = &union_obj.fields.values()[field_index]; |
| 8114 | const result_llvm_ty = try self.dg.llvmType(self.air.typeOfIndex(inst)); | 8114 | const result_llvm_ty = try self.dg.lowerType(self.air.typeOfIndex(inst)); |
| 8115 | if (!field.ty.hasRuntimeBitsIgnoreComptime()) { | 8115 | if (!field.ty.hasRuntimeBitsIgnoreComptime()) { |
| 8116 | return null; | 8116 | return null; |
| 8117 | } | 8117 | } |
| ... | @@ -8150,7 +8150,7 @@ pub const FuncGen = struct { | ... | @@ -8150,7 +8150,7 @@ pub const FuncGen = struct { |
| 8150 | const ptr_volatile = llvm.Bool.fromBool(ptr_ty.isVolatilePtr()); | 8150 | const ptr_volatile = llvm.Bool.fromBool(ptr_ty.isVolatilePtr()); |
| 8151 | if (info.host_size == 0) { | 8151 | if (info.host_size == 0) { |
| 8152 | if (isByRef(info.pointee_type)) { | 8152 | if (isByRef(info.pointee_type)) { |
| 8153 | const elem_llvm_ty = try self.dg.llvmType(info.pointee_type); | 8153 | const elem_llvm_ty = try self.dg.lowerType(info.pointee_type); |
| 8154 | const result_align = info.pointee_type.abiAlignment(target); | 8154 | const result_align = info.pointee_type.abiAlignment(target); |
| 8155 | const max_align = @maximum(result_align, ptr_alignment); | 8155 | const max_align = @maximum(result_align, ptr_alignment); |
| 8156 | const result_ptr = self.buildAlloca(elem_llvm_ty); | 8156 | const result_ptr = self.buildAlloca(elem_llvm_ty); |
| ... | @@ -8183,7 +8183,7 @@ pub const FuncGen = struct { | ... | @@ -8183,7 +8183,7 @@ pub const FuncGen = struct { |
| 8183 | const elem_bits = @intCast(c_uint, ptr_ty.elemType().bitSize(target)); | 8183 | const elem_bits = @intCast(c_uint, ptr_ty.elemType().bitSize(target)); |
| 8184 | const shift_amt = containing_int.typeOf().constInt(info.bit_offset, .False); | 8184 | const shift_amt = containing_int.typeOf().constInt(info.bit_offset, .False); |
| 8185 | const shifted_value = self.builder.buildLShr(containing_int, shift_amt, ""); | 8185 | const shifted_value = self.builder.buildLShr(containing_int, shift_amt, ""); |
| 8186 | const elem_llvm_ty = try self.dg.llvmType(info.pointee_type); | 8186 | const elem_llvm_ty = try self.dg.lowerType(info.pointee_type); |
| 8187 | | 8187 | |
| 8188 | if (isByRef(info.pointee_type)) { | 8188 | if (isByRef(info.pointee_type)) { |
| 8189 | const result_align = info.pointee_type.abiAlignment(target); | 8189 | const result_align = info.pointee_type.abiAlignment(target); |
| ... | @@ -8625,7 +8625,7 @@ fn lowerFnRetTy(dg: *DeclGen, fn_info: Type.Payload.Function.Data) !*const llvm. | ... | @@ -8625,7 +8625,7 @@ fn lowerFnRetTy(dg: *DeclGen, fn_info: Type.Payload.Function.Data) !*const llvm. |
| 8625 | // anyerror return type instead, so that it can be coerced into a function | 8625 | // anyerror return type instead, so that it can be coerced into a function |
| 8626 | // pointer type which has anyerror as the return type. | 8626 | // pointer type which has anyerror as the return type. |
| 8627 | if (fn_info.return_type.isError()) { | 8627 | if (fn_info.return_type.isError()) { |
| 8628 | return dg.llvmType(Type.anyerror); | 8628 | return dg.lowerType(Type.anyerror); |
| 8629 | } else { | 8629 | } else { |
| 8630 | return dg.context.voidType(); | 8630 | return dg.context.voidType(); |
| 8631 | } | 8631 | } |
| ... | @@ -8636,7 +8636,7 @@ fn lowerFnRetTy(dg: *DeclGen, fn_info: Type.Payload.Function.Data) !*const llvm. | ... | @@ -8636,7 +8636,7 @@ fn lowerFnRetTy(dg: *DeclGen, fn_info: Type.Payload.Function.Data) !*const llvm. |
| 8636 | if (isByRef(fn_info.return_type)) { | 8636 | if (isByRef(fn_info.return_type)) { |
| 8637 | return dg.context.voidType(); | 8637 | return dg.context.voidType(); |
| 8638 | } else { | 8638 | } else { |
| 8639 | return dg.llvmType(fn_info.return_type); | 8639 | return dg.lowerType(fn_info.return_type); |
| 8640 | } | 8640 | } |
| 8641 | }, | 8641 | }, |
| 8642 | .C => { | 8642 | .C => { |
| ... | @@ -8657,24 +8657,24 @@ fn lowerFnRetTy(dg: *DeclGen, fn_info: Type.Payload.Function.Data) !*const llvm. | ... | @@ -8657,24 +8657,24 @@ fn lowerFnRetTy(dg: *DeclGen, fn_info: Type.Payload.Function.Data) !*const llvm. |
| 8657 | else => false, | 8657 | else => false, |
| 8658 | }; | 8658 | }; |
| 8659 | switch (target.cpu.arch) { | 8659 | switch (target.cpu.arch) { |
| 8660 | .mips, .mipsel => return dg.llvmType(fn_info.return_type), | 8660 | .mips, .mipsel => return dg.lowerType(fn_info.return_type), |
| 8661 | .x86_64 => switch (target.os.tag) { | 8661 | .x86_64 => switch (target.os.tag) { |
| 8662 | .windows => switch (x86_64_abi.classifyWindows(fn_info.return_type, target)) { | 8662 | .windows => switch (x86_64_abi.classifyWindows(fn_info.return_type, target)) { |
| 8663 | .integer => { | 8663 | .integer => { |
| 8664 | if (is_scalar) { | 8664 | if (is_scalar) { |
| 8665 | return dg.llvmType(fn_info.return_type); | 8665 | return dg.lowerType(fn_info.return_type); |
| 8666 | } else { | 8666 | } else { |
| 8667 | const abi_size = fn_info.return_type.abiSize(target); | 8667 | const abi_size = fn_info.return_type.abiSize(target); |
| 8668 | return dg.context.intType(@intCast(c_uint, abi_size * 8)); | 8668 | return dg.context.intType(@intCast(c_uint, abi_size * 8)); |
| 8669 | } | 8669 | } |
| 8670 | }, | 8670 | }, |
| 8671 | .memory => return dg.context.voidType(), | 8671 | .memory => return dg.context.voidType(), |
| 8672 | .sse => return dg.llvmType(fn_info.return_type), | 8672 | .sse => return dg.lowerType(fn_info.return_type), |
| 8673 | else => unreachable, | 8673 | else => unreachable, |
| 8674 | }, | 8674 | }, |
| 8675 | else => { | 8675 | else => { |
| 8676 | if (is_scalar) { | 8676 | if (is_scalar) { |
| 8677 | return dg.llvmType(fn_info.return_type); | 8677 | return dg.lowerType(fn_info.return_type); |
| 8678 | } | 8678 | } |
| 8679 | const classes = x86_64_abi.classifySystemV(fn_info.return_type, target); | 8679 | const classes = x86_64_abi.classifySystemV(fn_info.return_type, target); |
| 8680 | if (classes[0] == .memory) { | 8680 | if (classes[0] == .memory) { |
| ... | @@ -8715,10 +8715,10 @@ fn lowerFnRetTy(dg: *DeclGen, fn_info: Type.Payload.Function.Data) !*const llvm. | ... | @@ -8715,10 +8715,10 @@ fn lowerFnRetTy(dg: *DeclGen, fn_info: Type.Payload.Function.Data) !*const llvm. |
| 8715 | }, | 8715 | }, |
| 8716 | }, | 8716 | }, |
| 8717 | // TODO investigate C ABI for other architectures | 8717 | // TODO investigate C ABI for other architectures |
| 8718 | else => return dg.llvmType(fn_info.return_type), | 8718 | else => return dg.lowerType(fn_info.return_type), |
| 8719 | } | 8719 | } |
| 8720 | }, | 8720 | }, |
| 8721 | else => return dg.llvmType(fn_info.return_type), | 8721 | else => return dg.lowerType(fn_info.return_type), |
| 8722 | } | 8722 | } |
| 8723 | } | 8723 | } |
| 8724 | | 8724 | |