authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-05-23 21:05:24-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-05-24 15:34:52-07:00
logcd59b8277d018a3418267b9fa0c219debdff5ca3
treefe9b61a650c941604bec763da38435c7374bfe64
parent7db39384f7384b73c51dd9cab5b23ad0a3699fd0

LLVM: rename two functions

llvmType -> lowerType genTypedValue -> lowerValue

1 files changed, 183 insertions(+), 183 deletions(-)

src/codegen/llvm.zig+183-183
......@@ -745,7 +745,7 @@ pub const Object = struct {
745745 const param = llvm_func.getParam(llvm_arg_i);
746746 llvm_arg_i += 1;
747747
748 const param_llvm_ty = try dg.llvmType(param_ty);
748 const param_llvm_ty = try dg.lowerType(param_ty);
749749 const abi_size = @intCast(c_uint, param_ty.abiSize(target));
750750 const int_llvm_ty = dg.context.intType(abi_size * 8);
751751 const int_ptr_llvm_ty = int_llvm_ty.pointerType(0);
......@@ -775,7 +775,7 @@ pub const Object = struct {
775775 .Struct => {
776776 const fields = param_ty.structFields().values();
777777 if (is_by_ref) {
778 const param_llvm_ty = try dg.llvmType(param_ty);
778 const param_llvm_ty = try dg.lowerType(param_ty);
779779 const arg_ptr = buildAllocaInner(builder, llvm_func, false, param_llvm_ty);
780780 arg_ptr.setAlignment(param_ty.abiAlignment(target));
781781
......@@ -2100,7 +2100,7 @@ pub const DeclGen = struct {
21002100 break :init_val decl.val;
21012101 };
21022102 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 });
21042104 if (global.globalGetValueType() == llvm_init.typeOf()) {
21052105 global.setInitializer(llvm_init);
21062106 } else {
......@@ -2171,7 +2171,7 @@ pub const DeclGen = struct {
21712171 const target = dg.module.getTarget();
21722172 const sret = firstParamSRet(fn_info, target);
21732173
2174 const fn_type = try dg.llvmType(zig_fn_type);
2174 const fn_type = try dg.lowerType(zig_fn_type);
21752175
21762176 const fqn = try decl.getFullyQualifiedName(dg.module);
21772177 defer dg.gpa.free(fqn);
......@@ -2198,7 +2198,7 @@ pub const DeclGen = struct {
21982198 dg.addArgAttr(llvm_fn, 0, "nonnull"); // Sret pointers must not be address 0
21992199 dg.addArgAttr(llvm_fn, 0, "noalias");
22002200
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);
22022202 llvm_fn.addSretAttr(0, raw_llvm_ret_ty);
22032203 }
22042204
......@@ -2291,7 +2291,7 @@ pub const DeclGen = struct {
22912291 const fqn = try decl.getFullyQualifiedName(dg.module);
22922292 defer dg.gpa.free(fqn);
22932293
2294 const llvm_type = try dg.llvmType(decl.ty);
2294 const llvm_type = try dg.lowerType(decl.ty);
22952295 const llvm_addrspace = dg.llvmAddressSpace(decl.@"addrspace");
22962296 const llvm_global = dg.object.llvm_module.addGlobalInAddressSpace(llvm_type, fqn, llvm_addrspace);
22972297 gop.value_ptr.* = llvm_global;
......@@ -2345,15 +2345,15 @@ pub const DeclGen = struct {
23452345 }
23462346
23472347 fn isUnnamedType(dg: *DeclGen, ty: Type, val: *const llvm.Value) bool {
2348 // Once `llvmType` 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
2348 // Once `lowerType` succeeds, successive calls to it with the same Zig type
2349 // are guaranteed to succeed. So if a call to `lowerType` fails here it means
23502350 // it is the first time lowering the type, which means the value can't possible
23512351 // have that type.
2352 const llvm_ty = dg.llvmType(ty) catch return true;
2352 const llvm_ty = dg.lowerType(ty) catch return true;
23532353 return val.typeOf() != llvm_ty;
23542354 }
23552355
2356 fn llvmType(dg: *DeclGen, t: Type) Allocator.Error!*const llvm.Type {
2356 fn lowerType(dg: *DeclGen, t: Type) Allocator.Error!*const llvm.Type {
23572357 const gpa = dg.gpa;
23582358 const target = dg.module.getTarget();
23592359 switch (t.zigTypeTag()) {
......@@ -2385,8 +2385,8 @@ pub const DeclGen = struct {
23852385 const ptr_type = t.slicePtrFieldType(&buf);
23862386
23872387 const fields: [2]*const llvm.Type = .{
2388 try dg.llvmType(ptr_type),
2389 try dg.llvmType(Type.usize),
2388 try dg.lowerType(ptr_type),
2389 try dg.lowerType(Type.usize),
23902390 };
23912391 return dg.context.structType(&fields, fields.len, .False);
23922392 }
......@@ -2402,7 +2402,7 @@ pub const DeclGen = struct {
24022402 else => elem_ty.hasRuntimeBitsIgnoreComptime(),
24032403 };
24042404 const llvm_elem_ty = if (lower_elem_ty)
2405 try dg.llvmType(elem_ty)
2405 try dg.lowerType(elem_ty)
24062406 else
24072407 dg.context.intType(8);
24082408 return llvm_elem_ty.pointerType(llvm_addrspace);
......@@ -2430,12 +2430,12 @@ pub const DeclGen = struct {
24302430 .Array => {
24312431 const elem_ty = t.childType();
24322432 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);
24342434 const total_len = t.arrayLen() + @boolToInt(t.sentinel() != null);
24352435 return elem_llvm_ty.arrayType(@intCast(c_uint, total_len));
24362436 },
24372437 .Vector => {
2438 const elem_type = try dg.llvmType(t.childType());
2438 const elem_type = try dg.lowerType(t.childType());
24392439 return elem_type.vectorType(t.vectorLen());
24402440 },
24412441 .Optional => {
......@@ -2444,7 +2444,7 @@ pub const DeclGen = struct {
24442444 if (!child_ty.hasRuntimeBitsIgnoreComptime()) {
24452445 return dg.context.intType(1);
24462446 }
2447 const payload_llvm_ty = try dg.llvmType(child_ty);
2447 const payload_llvm_ty = try dg.lowerType(child_ty);
24482448 if (t.optionalReprIsPayload()) {
24492449 return payload_llvm_ty;
24502450 }
......@@ -2458,13 +2458,13 @@ pub const DeclGen = struct {
24582458 const error_type = t.errorUnionSet();
24592459 const payload_type = t.errorUnionPayload();
24602460 if (error_type.errorSetCardinality() == .zero) {
2461 return dg.llvmType(payload_type);
2461 return dg.lowerType(payload_type);
24622462 }
24632463 if (!payload_type.hasRuntimeBitsIgnoreComptime()) {
2464 return try dg.llvmType(Type.anyerror);
2464 return try dg.lowerType(Type.anyerror);
24652465 }
2466 const llvm_error_type = try dg.llvmType(error_type);
2467 const llvm_payload_type = try dg.llvmType(payload_type);
2466 const llvm_error_type = try dg.lowerType(error_type);
2467 const llvm_payload_type = try dg.lowerType(payload_type);
24682468
24692469 const payload_align = payload_type.abiAlignment(target);
24702470 const error_align = Type.anyerror.abiAlignment(target);
......@@ -2515,7 +2515,7 @@ pub const DeclGen = struct {
25152515 const llvm_array_ty = dg.context.intType(8).arrayType(@intCast(c_uint, padding_len));
25162516 try llvm_field_types.append(gpa, llvm_array_ty);
25172517 }
2518 const field_llvm_ty = try dg.llvmType(field_ty);
2518 const field_llvm_ty = try dg.lowerType(field_ty);
25192519 try llvm_field_types.append(gpa, field_llvm_ty);
25202520
25212521 offset += field_ty.abiSize(target);
......@@ -2544,7 +2544,7 @@ pub const DeclGen = struct {
25442544 if (struct_obj.layout == .Packed) {
25452545 var buf: Type.Payload.Bits = undefined;
25462546 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);
25482548 gop.value_ptr.* = int_llvm_ty;
25492549 return int_llvm_ty;
25502550 }
......@@ -2579,7 +2579,7 @@ pub const DeclGen = struct {
25792579 const llvm_array_ty = dg.context.intType(8).arrayType(@intCast(c_uint, padding_len));
25802580 try llvm_field_types.append(gpa, llvm_array_ty);
25812581 }
2582 const field_llvm_ty = try dg.llvmType(field.ty);
2582 const field_llvm_ty = try dg.lowerType(field.ty);
25832583 try llvm_field_types.append(gpa, field_llvm_ty);
25842584
25852585 offset += field.ty.abiSize(target);
......@@ -2614,7 +2614,7 @@ pub const DeclGen = struct {
26142614 const union_obj = t.cast(Type.Payload.Union).?.data;
26152615
26162616 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);
26182618 gop.value_ptr.* = enum_tag_llvm_ty;
26192619 return enum_tag_llvm_ty;
26202620 }
......@@ -2626,7 +2626,7 @@ pub const DeclGen = struct {
26262626 gop.value_ptr.* = llvm_union_ty; // must be done before any recursive calls
26272627
26282628 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);
26302630
26312631 const llvm_payload_ty = t: {
26322632 if (layout.most_aligned_field_size == layout.payload_size) {
......@@ -2645,7 +2645,7 @@ pub const DeclGen = struct {
26452645 llvm_union_ty.structSetBody(&llvm_fields, llvm_fields.len, .False);
26462646 return llvm_union_ty;
26472647 }
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);
26492649
26502650 // Put the tag before or after the payload depending on which one's
26512651 // alignment is greater.
......@@ -2667,7 +2667,7 @@ pub const DeclGen = struct {
26672667 llvm_union_ty.structSetBody(&llvm_fields, llvm_fields_len, .False);
26682668 return llvm_union_ty;
26692669 },
2670 .Fn => return llvmTypeFn(dg, t),
2670 .Fn => return lowerTypeFn(dg, t),
26712671 .ComptimeInt => unreachable,
26722672 .ComptimeFloat => unreachable,
26732673 .Type => unreachable,
......@@ -2682,7 +2682,7 @@ pub const DeclGen = struct {
26822682 }
26832683 }
26842684
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 {
26862686 const target = dg.module.getTarget();
26872687 const fn_info = fn_ty.fnInfo();
26882688 const llvm_ret_ty = try lowerFnRetTy(dg, fn_info);
......@@ -2691,7 +2691,7 @@ pub const DeclGen = struct {
26912691 defer llvm_params.deinit();
26922692
26932693 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);
26952695 try llvm_params.append(llvm_sret_ty.pointerType(0));
26962696 }
26972697
......@@ -2703,7 +2703,7 @@ pub const DeclGen = struct {
27032703 .data = dg.object.getStackTraceType(),
27042704 };
27052705 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));
27072707 }
27082708
27092709 var it = iterateParamTypes(dg, fn_info);
......@@ -2711,11 +2711,11 @@ pub const DeclGen = struct {
27112711 .no_bits => continue,
27122712 .byval => {
27132713 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));
27152715 },
27162716 .byref => {
27172717 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);
27192719 try llvm_params.append(raw_llvm_ty.pointerType(0));
27202720 },
27212721 .abi_sized_int => {
......@@ -2757,7 +2757,7 @@ pub const DeclGen = struct {
27572757 // one field; in this case keep the type information
27582758 // to avoid the potentially costly ptrtoint/bitcast.
27592759 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);
27612761 llvm_params.appendAssumeCapacity(llvm_field_ty);
27622762 field_i += 1;
27632763 if (field_i >= fields.len) {
......@@ -2795,16 +2795,16 @@ pub const DeclGen = struct {
27952795 );
27962796 }
27972797
2798 fn genTypedValue(dg: *DeclGen, tv: TypedValue) Error!*const llvm.Value {
2798 fn lowerValue(dg: *DeclGen, tv: TypedValue) Error!*const llvm.Value {
27992799 if (tv.val.isUndef()) {
2800 const llvm_type = try dg.llvmType(tv.ty);
2800 const llvm_type = try dg.lowerType(tv.ty);
28012801 return llvm_type.getUndef();
28022802 }
28032803 const target = dg.module.getTarget();
28042804
28052805 switch (tv.ty.zigTypeTag()) {
28062806 .Bool => {
2807 const llvm_type = try dg.llvmType(tv.ty);
2807 const llvm_type = try dg.lowerType(tv.ty);
28082808 return if (tv.val.toBool()) llvm_type.constAllOnes() else llvm_type.constNull();
28092809 },
28102810 // TODO this duplicates code with Pointer but they should share the handling
......@@ -2865,7 +2865,7 @@ pub const DeclGen = struct {
28652865 return unsigned_val;
28662866 },
28672867 .Float => {
2868 const llvm_ty = try dg.llvmType(tv.ty);
2868 const llvm_ty = try dg.lowerType(tv.ty);
28692869 switch (tv.ty.floatBits(target)) {
28702870 16, 32, 64 => return llvm_ty.constReal(tv.val.toFloat(f64)),
28712871 80 => {
......@@ -2902,7 +2902,7 @@ pub const DeclGen = struct {
29022902 const decl = dg.module.declPtr(decl_index);
29032903 dg.module.markDeclAlive(decl);
29042904 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);
29062906 const llvm_addrspace = dg.llvmAddressSpace(decl.@"addrspace");
29072907 const llvm_type = llvm_var_type.pointerType(llvm_addrspace);
29082908 return val.constBitCast(llvm_type);
......@@ -2911,11 +2911,11 @@ pub const DeclGen = struct {
29112911 const slice = tv.val.castTag(.slice).?.data;
29122912 var buf: Type.SlicePtrFieldTypeBuffer = undefined;
29132913 const fields: [2]*const llvm.Value = .{
2914 try dg.genTypedValue(.{
2914 try dg.lowerValue(.{
29152915 .ty = tv.ty.slicePtrFieldType(&buf),
29162916 .val = slice.ptr,
29172917 }),
2918 try dg.genTypedValue(.{
2918 try dg.lowerValue(.{
29192919 .ty = Type.usize,
29202920 .val = slice.len,
29212921 }),
......@@ -2923,15 +2923,15 @@ pub const DeclGen = struct {
29232923 return dg.context.constStruct(&fields, fields.len, .False);
29242924 },
29252925 .int_u64, .one, .int_big_positive => {
2926 const llvm_usize = try dg.llvmType(Type.usize);
2926 const llvm_usize = try dg.lowerType(Type.usize);
29272927 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));
29292929 },
29302930 .field_ptr, .opt_payload_ptr, .eu_payload_ptr, .elem_ptr => {
29312931 return dg.lowerParentPtr(tv.val, tv.ty.childType());
29322932 },
29332933 .null_value, .zero => {
2934 const llvm_type = try dg.llvmType(tv.ty);
2934 const llvm_type = try dg.lowerType(tv.ty);
29352935 return llvm_type.constNull();
29362936 },
29372937 else => |tag| return dg.todo("implement const of pointer type '{}' ({})", .{
......@@ -2986,7 +2986,7 @@ pub const DeclGen = struct {
29862986 defer gpa.free(llvm_elems);
29872987 var need_unnamed = false;
29882988 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 });
29902990 need_unnamed = need_unnamed or dg.isUnnamedType(elem_ty, llvm_elems[i]);
29912991 }
29922992 if (need_unnamed) {
......@@ -2996,7 +2996,7 @@ pub const DeclGen = struct {
29962996 .True,
29972997 );
29982998 } else {
2999 const llvm_elem_ty = try dg.llvmType(elem_ty);
2999 const llvm_elem_ty = try dg.lowerType(elem_ty);
30003000 return llvm_elem_ty.constArray(
30013001 llvm_elems.ptr,
30023002 @intCast(c_uint, llvm_elems.len),
......@@ -3016,13 +3016,13 @@ pub const DeclGen = struct {
30163016 var need_unnamed = false;
30173017 if (len != 0) {
30183018 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 });
30203020 }
30213021 need_unnamed = need_unnamed or dg.isUnnamedType(elem_ty, llvm_elems[0]);
30223022 }
30233023
30243024 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 });
30263026 need_unnamed = need_unnamed or dg.isUnnamedType(elem_ty, llvm_elems[len]);
30273027 }
30283028
......@@ -3033,7 +3033,7 @@ pub const DeclGen = struct {
30333033 .True,
30343034 );
30353035 } else {
3036 const llvm_elem_ty = try dg.llvmType(elem_ty);
3036 const llvm_elem_ty = try dg.lowerType(elem_ty);
30373037 return llvm_elem_ty.constArray(
30383038 llvm_elems.ptr,
30393039 @intCast(c_uint, llvm_elems.len),
......@@ -3043,13 +3043,13 @@ pub const DeclGen = struct {
30433043 .empty_array_sentinel => {
30443044 const elem_ty = tv.ty.elemType();
30453045 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 });
30473047 const llvm_elems: [1]*const llvm.Value = .{sentinel};
30483048 const need_unnamed = dg.isUnnamedType(elem_ty, llvm_elems[0]);
30493049 if (need_unnamed) {
30503050 return dg.context.constStruct(&llvm_elems, llvm_elems.len, .True);
30513051 } else {
3052 const llvm_elem_ty = try dg.llvmType(elem_ty);
3052 const llvm_elem_ty = try dg.lowerType(elem_ty);
30533053 return llvm_elem_ty.constArray(&llvm_elems, llvm_elems.len);
30543054 }
30553055 },
......@@ -3066,17 +3066,17 @@ pub const DeclGen = struct {
30663066 }
30673067 if (tv.ty.optionalReprIsPayload()) {
30683068 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 });
30703070 } else if (is_pl) {
3071 return dg.genTypedValue(.{ .ty = payload_ty, .val = tv.val });
3071 return dg.lowerValue(.{ .ty = payload_ty, .val = tv.val });
30723072 } else {
3073 const llvm_ty = try dg.llvmType(tv.ty);
3073 const llvm_ty = try dg.lowerType(tv.ty);
30743074 return llvm_ty.constNull();
30753075 }
30763076 }
30773077 assert(payload_ty.zigTypeTag() != .Fn);
30783078 const fields: [2]*const llvm.Value = .{
3079 try dg.genTypedValue(.{
3079 try dg.lowerValue(.{
30803080 .ty = payload_ty,
30813081 .val = if (tv.val.castTag(.opt_payload)) |pl| pl.data else Value.initTag(.undef),
30823082 }),
......@@ -3095,7 +3095,7 @@ pub const DeclGen = struct {
30953095 return dg.resolveLlvmFunction(fn_decl_index);
30963096 },
30973097 .ErrorSet => {
3098 const llvm_ty = try dg.llvmType(tv.ty);
3098 const llvm_ty = try dg.lowerType(tv.ty);
30993099 switch (tv.val.tag()) {
31003100 .@"error" => {
31013101 const err_name = tv.val.castTag(.@"error").?.data.name;
......@@ -3113,23 +3113,23 @@ pub const DeclGen = struct {
31133113 const payload_type = tv.ty.errorUnionPayload();
31143114 if (error_type.errorSetCardinality() == .zero) {
31153115 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 });
31173117 }
31183118 const is_pl = tv.val.errorUnionIsPayload();
31193119
31203120 if (!payload_type.hasRuntimeBitsIgnoreComptime()) {
31213121 // We use the error type directly as the type.
31223122 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 });
31243124 }
31253125
31263126 const payload_align = payload_type.abiAlignment(target);
31273127 const error_align = Type.anyerror.abiAlignment(target);
3128 const llvm_error_value = try dg.genTypedValue(.{
3128 const llvm_error_value = try dg.lowerValue(.{
31293129 .ty = error_type,
31303130 .val = if (is_pl) Value.initTag(.zero) else tv.val,
31313131 });
3132 const llvm_payload_value = try dg.genTypedValue(.{
3132 const llvm_payload_value = try dg.lowerValue(.{
31333133 .ty = payload_type,
31343134 .val = if (tv.val.castTag(.eu_payload)) |pl| pl.data else Value.initTag(.undef),
31353135 });
......@@ -3142,7 +3142,7 @@ pub const DeclGen = struct {
31423142 }
31433143 },
31443144 .Struct => {
3145 const llvm_struct_ty = try dg.llvmType(tv.ty);
3145 const llvm_struct_ty = try dg.lowerType(tv.ty);
31463146 const field_vals = tv.val.castTag(.aggregate).?.data;
31473147 const gpa = dg.gpa;
31483148
......@@ -3175,7 +3175,7 @@ pub const DeclGen = struct {
31753175 llvm_fields.appendAssumeCapacity(llvm_array_ty.getUndef());
31763176 }
31773177
3178 const field_llvm_val = try dg.genTypedValue(.{
3178 const field_llvm_val = try dg.lowerValue(.{
31793179 .ty = field_ty,
31803180 .val = field_vals[i],
31813181 });
......@@ -3223,7 +3223,7 @@ pub const DeclGen = struct {
32233223 const field = fields[i];
32243224 if (!field.ty.hasRuntimeBitsIgnoreComptime()) continue;
32253225
3226 const non_int_val = try dg.genTypedValue(.{
3226 const non_int_val = try dg.lowerValue(.{
32273227 .ty = field.ty,
32283228 .val = field_val,
32293229 });
......@@ -3267,7 +3267,7 @@ pub const DeclGen = struct {
32673267 llvm_fields.appendAssumeCapacity(llvm_array_ty.getUndef());
32683268 }
32693269
3270 const field_llvm_val = try dg.genTypedValue(.{
3270 const field_llvm_val = try dg.lowerValue(.{
32713271 .ty = field.ty,
32723272 .val = field_vals[i],
32733273 });
......@@ -3302,13 +3302,13 @@ pub const DeclGen = struct {
33023302 }
33033303 },
33043304 .Union => {
3305 const llvm_union_ty = try dg.llvmType(tv.ty);
3305 const llvm_union_ty = try dg.lowerType(tv.ty);
33063306 const tag_and_val = tv.val.castTag(.@"union").?.data;
33073307
33083308 const layout = tv.ty.unionGetLayout(target);
33093309
33103310 if (layout.payload_size == 0) {
3311 return genTypedValue(dg, .{
3311 return lowerValue(dg, .{
33123312 .ty = tv.ty.unionTagType().?,
33133313 .val = tag_and_val.tag,
33143314 });
......@@ -3322,7 +3322,7 @@ pub const DeclGen = struct {
33223322 const padding_len = @intCast(c_uint, layout.payload_size);
33233323 break :p dg.context.intType(8).arrayType(padding_len).getUndef();
33243324 }
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 });
33263326 const field_size = field_ty.abiSize(target);
33273327 if (field_size == layout.payload_size) {
33283328 break :p field;
......@@ -3348,7 +3348,7 @@ pub const DeclGen = struct {
33483348 return llvm_union_ty.constNamedStruct(&fields, fields.len);
33493349 }
33503350 }
3351 const llvm_tag_value = try genTypedValue(dg, .{
3351 const llvm_tag_value = try lowerValue(dg, .{
33523352 .ty = tv.ty.unionTagType().?,
33533353 .val = tag_and_val.tag,
33543354 });
......@@ -3385,7 +3385,7 @@ pub const DeclGen = struct {
33853385 .data = bytes[i],
33863386 };
33873387
3388 elem.* = try dg.genTypedValue(.{
3388 elem.* = try dg.lowerValue(.{
33893389 .ty = elem_ty,
33903390 .val = Value.initPayload(&byte_payload.base),
33913391 });
......@@ -3405,7 +3405,7 @@ pub const DeclGen = struct {
34053405 const llvm_elems = try dg.gpa.alloc(*const llvm.Value, vector_len);
34063406 defer dg.gpa.free(llvm_elems);
34073407 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] });
34093409 }
34103410 return llvm.constVector(
34113411 llvm_elems.ptr,
......@@ -3420,7 +3420,7 @@ pub const DeclGen = struct {
34203420 const llvm_elems = try dg.gpa.alloc(*const llvm.Value, len);
34213421 defer dg.gpa.free(llvm_elems);
34223422 for (llvm_elems) |*elem| {
3423 elem.* = try dg.genTypedValue(.{ .ty = elem_ty, .val = val });
3423 elem.* = try dg.lowerValue(.{ .ty = elem_ty, .val = val });
34243424 }
34253425 return llvm.constVector(
34263426 llvm_elems.ptr,
......@@ -3470,7 +3470,7 @@ pub const DeclGen = struct {
34703470 if (ptr_child_ty.eql(decl.ty, dg.module)) {
34713471 return llvm_ptr;
34723472 } 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));
34743474 }
34753475 }
34763476
......@@ -3492,15 +3492,15 @@ pub const DeclGen = struct {
34923492 },
34933493 .int_i64 => {
34943494 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);
34963496 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));
34983498 },
34993499 .int_u64 => {
35003500 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);
35023502 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));
35043504 },
35053505 .field_ptr => blk: {
35063506 const field_ptr = ptr_val.castTag(.field_ptr).?.data;
......@@ -3549,7 +3549,7 @@ pub const DeclGen = struct {
35493549 const parent_llvm_ptr = try dg.lowerParentPtr(elem_ptr.array_ptr, elem_ptr.elem_ty);
35503550 bitcast_needed = !elem_ptr.elem_ty.eql(ptr_child_ty, dg.module);
35513551
3552 const llvm_usize = try dg.llvmType(Type.usize);
3552 const llvm_usize = try dg.lowerType(Type.usize);
35533553 const indices: [1]*const llvm.Value = .{
35543554 llvm_usize.constInt(elem_ptr.index, .False),
35553555 };
......@@ -3602,7 +3602,7 @@ pub const DeclGen = struct {
36023602 else => unreachable,
36033603 };
36043604 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));
36063606 } else {
36073607 return llvm_ptr;
36083608 }
......@@ -3621,11 +3621,11 @@ pub const DeclGen = struct {
36213621 .data = tv.val.sliceLen(self.module),
36223622 };
36233623 const fields: [2]*const llvm.Value = .{
3624 try self.genTypedValue(.{
3624 try self.lowerValue(.{
36253625 .ty = ptr_ty,
36263626 .val = tv.val,
36273627 }),
3628 try self.genTypedValue(.{
3628 try self.lowerValue(.{
36293629 .ty = Type.usize,
36303630 .val = Value.initPayload(&slice_len.base),
36313631 }),
......@@ -3657,7 +3657,7 @@ pub const DeclGen = struct {
36573657 else
36583658 try self.resolveGlobalDecl(decl_index);
36593659
3660 const llvm_type = try self.llvmType(tv.ty);
3660 const llvm_type = try self.lowerType(tv.ty);
36613661 if (tv.ty.zigTypeTag() == .Int) {
36623662 return llvm_val.constPtrToInt(llvm_type);
36633663 } else {
......@@ -3672,8 +3672,8 @@ pub const DeclGen = struct {
36723672 // The value cannot be undefined, because we use the `nonnull` annotation
36733673 // for non-optional pointers. We also need to respect the alignment, even though
36743674 // the address will never be dereferenced.
3675 const llvm_usize = try dg.llvmType(Type.usize);
3676 const llvm_ptr_ty = try dg.llvmType(ptr_ty);
3675 const llvm_usize = try dg.lowerType(Type.usize);
3676 const llvm_ptr_ty = try dg.lowerType(ptr_ty);
36773677 if (alignment != 0) {
36783678 return llvm_usize.constInt(alignment, .False).constIntToPtr(llvm_ptr_ty);
36793679 }
......@@ -3852,7 +3852,7 @@ pub const FuncGen = struct {
38523852
38533853 const val = self.air.value(inst).?;
38543854 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 });
38563856 if (!isByRef(ty)) {
38573857 gop.value_ptr.* = llvm_val;
38583858 return llvm_val;
......@@ -3870,7 +3870,7 @@ pub const FuncGen = struct {
38703870 // Because of LLVM limitations for lowering certain types such as unions,
38713871 // the type of global constants might not match the type it is supposed to
38723872 // 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);
38743874 const wanted_llvm_ptr_ty = wanted_llvm_ty.pointerType(0);
38753875 const casted_ptr = global.constBitCast(wanted_llvm_ptr_ty);
38763876 gop.value_ptr.* = casted_ptr;
......@@ -4094,7 +4094,7 @@ pub const FuncGen = struct {
40944094 defer llvm_args.deinit();
40954095
40964096 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);
40984098 const ret_ptr = self.buildAlloca(llvm_ret_ty);
40994099 ret_ptr.setAlignment(return_type.abiAlignment(target));
41004100 try llvm_args.append(ret_ptr);
......@@ -4126,7 +4126,7 @@ pub const FuncGen = struct {
41264126 // which is always lowered to an LLVM type of `*i8`.
41274127 // 2. The argument is a global which does act as a pointer, however
41284128 // 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);
41304130 const casted_ptr = self.builder.buildBitCast(llvm_arg, llvm_param_ty, "");
41314131 try llvm_args.append(casted_ptr);
41324132 } else {
......@@ -4173,7 +4173,7 @@ pub const FuncGen = struct {
41734173 );
41744174 const int_ptr = self.buildAlloca(int_llvm_ty);
41754175 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);
41774177 const casted_ptr = self.builder.buildBitCast(int_ptr, param_llvm_ty.pointerType(0), "");
41784178 const store_inst = self.builder.buildStore(llvm_arg, casted_ptr);
41794179 store_inst.setAlignment(alignment);
......@@ -4284,7 +4284,7 @@ pub const FuncGen = struct {
42844284 return null;
42854285 }
42864286
4287 const llvm_ret_ty = try self.dg.llvmType(return_type);
4287 const llvm_ret_ty = try self.dg.lowerType(return_type);
42884288
42894289 if (ret_ptr) |rp| {
42904290 call.setCallSret(llvm_ret_ty);
......@@ -4354,7 +4354,7 @@ pub const FuncGen = struct {
43544354 // Functions with an empty error set are emitted with an error code
43554355 // return type and return zero so they can be function pointers coerced
43564356 // 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);
43584358 _ = self.builder.buildRet(err_int.constInt(0, .False));
43594359 } else {
43604360 _ = self.builder.buildRetVoid();
......@@ -4393,7 +4393,7 @@ pub const FuncGen = struct {
43934393 // Functions with an empty error set are emitted with an error code
43944394 // return type and return zero so they can be function pointers coerced
43954395 // 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);
43974397 _ = self.builder.buildRet(err_int.constInt(0, .False));
43984398 } else {
43994399 _ = self.builder.buildRetVoid();
......@@ -4407,7 +4407,7 @@ pub const FuncGen = struct {
44074407 const ptr = try self.resolveInst(un_op);
44084408 const target = self.dg.module.getTarget();
44094409 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);
44114411 const casted_ptr = if (abi_ret_ty == llvm_ret_ty) ptr else p: {
44124412 const ptr_abi_ty = abi_ret_ty.pointerType(0);
44134413 break :p self.builder.buildBitCast(ptr, ptr_abi_ty, "");
......@@ -4588,7 +4588,7 @@ pub const FuncGen = struct {
45884588 const is_body = inst_ty.zigTypeTag() == .Fn;
45894589 if (!is_body and !inst_ty.hasRuntimeBitsIgnoreComptime()) return null;
45904590
4591 const raw_llvm_ty = try self.dg.llvmType(inst_ty);
4591 const raw_llvm_ty = try self.dg.lowerType(inst_ty);
45924592
45934593 const llvm_ty = ty: {
45944594 // If the zig tag type is a function, this represents an actual function body; not
......@@ -4728,9 +4728,9 @@ pub const FuncGen = struct {
47284728 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
47294729 const operand_ty = self.air.typeOf(ty_op.operand);
47304730 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);
47324732 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));
47344734 if (!array_ty.hasRuntimeBitsIgnoreComptime()) {
47354735 return self.builder.buildInsertValue(slice_llvm_ty.getUndef(), len, 1, "");
47364736 }
......@@ -4755,7 +4755,7 @@ pub const FuncGen = struct {
47554755
47564756 const dest_ty = self.air.typeOfIndex(inst);
47574757 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);
47594759 const target = self.dg.module.getTarget();
47604760
47614761 if (intrinsicsAllowed(dest_scalar_ty, target)) {
......@@ -4806,7 +4806,7 @@ pub const FuncGen = struct {
48064806
48074807 const dest_ty = self.air.typeOfIndex(inst);
48084808 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);
48104810
48114811 if (intrinsicsAllowed(operand_scalar_ty, target)) {
48124812 // TODO set fast math flag
......@@ -4833,7 +4833,7 @@ pub const FuncGen = struct {
48334833 compiler_rt_dest_abbrev,
48344834 }) catch unreachable;
48354835
4836 const operand_llvm_ty = try self.dg.llvmType(operand_ty);
4836 const operand_llvm_ty = try self.dg.lowerType(operand_ty);
48374837 const param_types = [1]*const llvm.Type{operand_llvm_ty};
48384838 const libc_fn = self.getLibcFunction(fn_name, &param_types, libc_ret_ty);
48394839 const params = [1]*const llvm.Value{operand};
......@@ -4994,7 +4994,7 @@ pub const FuncGen = struct {
49944994 const containing_int = struct_llvm_val;
49954995 const shift_amt = containing_int.typeOf().constInt(bit_offset, .False);
49964996 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);
49984998 if (field_ty.zigTypeTag() == .Float) {
49994999 const elem_bits = @intCast(c_uint, field_ty.bitSize(target));
50005000 const same_size_int = self.context.intType(elem_bits);
......@@ -5026,7 +5026,7 @@ pub const FuncGen = struct {
50265026 return self.load(field_ptr, field_ptr_ty);
50275027 },
50285028 .Union => {
5029 const llvm_field_ty = try self.dg.llvmType(field_ty);
5029 const llvm_field_ty = try self.dg.lowerType(field_ty);
50305030 const layout = struct_ty.unionGetLayout(target);
50315031 const payload_index = @boolToInt(layout.tag_align >= layout.payload_align);
50325032 const union_field_ptr = self.builder.buildStructGEP(struct_llvm_val, payload_index, "");
......@@ -5053,7 +5053,7 @@ pub const FuncGen = struct {
50535053 const struct_ty = self.air.getRefType(ty_pl.ty).childType();
50545054 const field_offset = struct_ty.structFieldOffset(extra.field_index, target);
50555055
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));
50575057 if (field_offset == 0) {
50585058 return self.builder.buildBitCast(field_ptr, res_ty, "");
50595059 }
......@@ -5383,7 +5383,7 @@ pub const FuncGen = struct {
53835383 }
53845384
53855385 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);
53875387 const llvm_fn_ty = llvm.functionType(
53885388 ret_llvm_ty,
53895389 llvm_param_types.ptr,
......@@ -5425,7 +5425,7 @@ pub const FuncGen = struct {
54255425 const operand_ty = self.air.typeOf(un_op);
54265426 const optional_ty = if (operand_is_ptr) operand_ty.childType() else operand_ty;
54275427 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);
54295429 const loaded = if (operand_is_ptr) self.builder.buildLoad(operand, "") else operand;
54305430 return self.builder.buildICmp(pred, loaded, optional_llvm_ty.constNull(), "");
54315431 }
......@@ -5462,7 +5462,7 @@ pub const FuncGen = struct {
54625462 const operand = try self.resolveInst(un_op);
54635463 const err_union_ty = self.air.typeOf(un_op);
54645464 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));
54665466 const zero = err_set_ty.constNull();
54675467
54685468 if (err_union_ty.errorUnionSet().errorSetCardinality() == .zero) {
......@@ -5506,7 +5506,7 @@ pub const FuncGen = struct {
55065506 // a pointer to a zero-bit value.
55075507
55085508 // 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);
55105510 return self.builder.buildBitCast(operand, res_ptr_ty, "");
55115511 }
55125512 if (optional_ty.optionalReprIsPayload()) {
......@@ -5534,7 +5534,7 @@ pub const FuncGen = struct {
55345534 _ = self.builder.buildStore(non_null_bit, operand);
55355535
55365536 // 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);
55385538 return self.builder.buildBitCast(operand, res_ptr_ty, "");
55395539 }
55405540 if (optional_ty.optionalReprIsPayload()) {
......@@ -5604,7 +5604,7 @@ pub const FuncGen = struct {
56045604 if (!operand_is_ptr) return null;
56055605
56065606 // 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);
56085608 return self.builder.buildBitCast(operand, res_ptr_ty, "");
56095609 }
56105610 if (operand_is_ptr or isByRef(payload_ty)) {
......@@ -5626,7 +5626,7 @@ pub const FuncGen = struct {
56265626 const operand_ty = self.air.typeOf(ty_op.operand);
56275627 const err_union_ty = if (operand_is_ptr) operand_ty.childType() else operand_ty;
56285628 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);
56305630 if (operand_is_ptr) {
56315631 return self.builder.buildBitCast(operand, err_llvm_ty.pointerType(0), "");
56325632 } else {
......@@ -5662,7 +5662,7 @@ pub const FuncGen = struct {
56625662 return operand;
56635663 }
56645664 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 });
56665666 if (!payload_ty.hasRuntimeBitsIgnoreComptime()) {
56675667 _ = self.builder.buildStore(non_error_val, operand);
56685668 return operand;
......@@ -5715,7 +5715,7 @@ pub const FuncGen = struct {
57155715 if (optional_ty.optionalReprIsPayload()) {
57165716 return operand;
57175717 }
5718 const llvm_optional_ty = try self.dg.llvmType(optional_ty);
5718 const llvm_optional_ty = try self.dg.lowerType(optional_ty);
57195719 if (isByRef(optional_ty)) {
57205720 const optional_ptr = self.buildAlloca(llvm_optional_ty);
57215721 const payload_ptr = self.builder.buildStructGEP(optional_ptr, 0, "");
......@@ -5746,8 +5746,8 @@ pub const FuncGen = struct {
57465746 if (!payload_ty.hasRuntimeBitsIgnoreComptime()) {
57475747 return operand;
57485748 }
5749 const ok_err_code = (try self.dg.llvmType(Type.anyerror)).constNull();
5750 const err_un_llvm_ty = try self.dg.llvmType(inst_ty);
5749 const ok_err_code = (try self.dg.lowerType(Type.anyerror)).constNull();
5750 const err_un_llvm_ty = try self.dg.lowerType(inst_ty);
57515751
57525752 const target = self.dg.module.getTarget();
57535753 const payload_offset = errUnionPayloadOffset(payload_ty, target);
......@@ -5781,7 +5781,7 @@ pub const FuncGen = struct {
57815781 if (!payload_ty.hasRuntimeBitsIgnoreComptime()) {
57825782 return operand;
57835783 }
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);
57855785
57865786 const target = self.dg.module.getTarget();
57875787 const payload_offset = errUnionPayloadOffset(payload_ty, target);
......@@ -5866,7 +5866,7 @@ pub const FuncGen = struct {
58665866 const ptr = try self.resolveInst(bin_op.lhs);
58675867 const len = try self.resolveInst(bin_op.rhs);
58685868 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);
58705870
58715871 // In case of slicing a global, the result type looks something like `{ i8*, i64 }`
58725872 // 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 {
58745874 // This prevents an assertion failure.
58755875 var buf: Type.SlicePtrFieldTypeBuffer = undefined;
58765876 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);
58785878 const casted_ptr = self.builder.buildBitCast(ptr, ptr_llvm_ty, "");
58795879 const partial = self.builder.buildInsertValue(llvm_slice_ty.getUndef(), casted_ptr, 0, "");
58805880 return self.builder.buildInsertValue(partial, len, 1, "");
......@@ -6040,7 +6040,7 @@ pub const FuncGen = struct {
60406040 // const d = @divTrunc(a, b);
60416041 // const r = @rem(a, b);
60426042 // 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);
60446044 const zero = result_llvm_ty.constNull();
60456045 const div_trunc = self.builder.buildSDiv(lhs, rhs, "");
60466046 const rem = self.builder.buildSRem(lhs, rhs, "");
......@@ -6090,7 +6090,7 @@ pub const FuncGen = struct {
60906090 const lhs = try self.resolveInst(bin_op.lhs);
60916091 const rhs = try self.resolveInst(bin_op.rhs);
60926092 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);
60946094 const scalar_ty = inst_ty.scalarType();
60956095
60966096 if (scalar_ty.isRuntimeFloat()) {
......@@ -6174,8 +6174,8 @@ pub const FuncGen = struct {
61746174
61756175 const intrinsic_name = if (scalar_ty.isSignedInt()) signed_intrinsic else unsigned_intrinsic;
61766176
6177 const llvm_lhs_ty = try self.dg.llvmType(lhs_ty);
6178 const llvm_dest_ty = try self.dg.llvmType(dest_ty);
6177 const llvm_lhs_ty = try self.dg.lowerType(lhs_ty);
6178 const llvm_dest_ty = try self.dg.lowerType(dest_ty);
61796179
61806180 const tg = self.dg.module.getTarget();
61816181
......@@ -6283,7 +6283,7 @@ pub const FuncGen = struct {
62836283 ) !*const llvm.Value {
62846284 const target = self.dg.module.getTarget();
62856285 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);
62876287
62886288 if (intrinsicsAllowed(scalar_ty, target)) {
62896289 const llvm_predicate: llvm.RealPredicate = switch (pred) {
......@@ -6383,8 +6383,8 @@ pub const FuncGen = struct {
63836383 ) !*const llvm.Value {
63846384 const target = self.dg.module.getTarget();
63856385 const scalar_ty = ty.scalarType();
6386 const llvm_ty = try self.dg.llvmType(ty);
6387 const scalar_llvm_ty = try self.dg.llvmType(scalar_ty);
6386 const llvm_ty = try self.dg.lowerType(ty);
6387 const scalar_llvm_ty = try self.dg.lowerType(scalar_ty);
63886388
63896389 const intrinsics_allowed = op != .tan and intrinsicsAllowed(scalar_ty, target);
63906390 var fn_name_buf: [64]u8 = undefined;
......@@ -6478,12 +6478,12 @@ pub const FuncGen = struct {
64786478 const rhs_scalar_ty = rhs_ty.scalarType();
64796479
64806480 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);
64826482
64836483 const tg = self.dg.module.getTarget();
64846484
64856485 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), "")
64876487 else
64886488 rhs;
64896489
......@@ -6543,7 +6543,7 @@ pub const FuncGen = struct {
65436543 const tg = self.dg.module.getTarget();
65446544
65456545 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), "")
65476547 else
65486548 rhs;
65496549 if (lhs_scalar_ty.isSignedInt()) return self.builder.buildNSWShl(lhs, casted_rhs, "");
......@@ -6566,7 +6566,7 @@ pub const FuncGen = struct {
65666566 const tg = self.dg.module.getTarget();
65676567
65686568 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), "")
65706570 else
65716571 rhs;
65726572 return self.builder.buildShl(lhs, casted_rhs, "");
......@@ -6588,7 +6588,7 @@ pub const FuncGen = struct {
65886588 const tg = self.dg.module.getTarget();
65896589
65906590 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), "")
65926592 else
65936593 rhs;
65946594 if (lhs_scalar_ty.isSignedInt()) return self.builder.buildSShlSat(lhs, casted_rhs, "");
......@@ -6611,7 +6611,7 @@ pub const FuncGen = struct {
66116611 const tg = self.dg.module.getTarget();
66126612
66136613 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), "")
66156615 else
66166616 rhs;
66176617 const is_signed_int = lhs_scalar_ty.isSignedInt();
......@@ -6639,7 +6639,7 @@ pub const FuncGen = struct {
66396639 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
66406640 const dest_ty = self.air.typeOfIndex(inst);
66416641 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);
66436643 const operand = try self.resolveInst(ty_op.operand);
66446644 const operand_ty = self.air.typeOf(ty_op.operand);
66456645 const operand_info = operand_ty.intInfo(target);
......@@ -6661,7 +6661,7 @@ pub const FuncGen = struct {
66616661
66626662 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
66636663 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));
66656665 return self.builder.buildTrunc(operand, dest_llvm_ty, "");
66666666 }
66676667
......@@ -6679,7 +6679,7 @@ pub const FuncGen = struct {
66796679 if (!backendSupportsF80(target) and (src_bits == 80 or dest_bits == 80)) {
66806680 return softF80TruncOrExt(self, operand, src_bits, dest_bits);
66816681 }
6682 const dest_llvm_ty = try self.dg.llvmType(dest_ty);
6682 const dest_llvm_ty = try self.dg.lowerType(dest_ty);
66836683 return self.builder.buildFPTrunc(operand, dest_llvm_ty, "");
66846684 }
66856685
......@@ -6697,7 +6697,7 @@ pub const FuncGen = struct {
66976697 if (!backendSupportsF80(target) and (src_bits == 80 or dest_bits == 80)) {
66986698 return softF80TruncOrExt(self, operand, src_bits, dest_bits);
66996699 }
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));
67016701 return self.builder.buildFPExt(operand, dest_llvm_ty, "");
67026702 }
67036703
......@@ -6707,7 +6707,7 @@ pub const FuncGen = struct {
67076707
67086708 const un_op = self.air.instructions.items(.data)[inst].un_op;
67096709 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));
67116711 return self.builder.buildPtrToInt(operand, dest_llvm_ty, "");
67126712 }
67136713
......@@ -6720,7 +6720,7 @@ pub const FuncGen = struct {
67206720 const inst_ty = self.air.typeOfIndex(inst);
67216721 const operand_is_ref = isByRef(operand_ty);
67226722 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);
67246724 const target = self.dg.module.getTarget();
67256725
67266726 if (operand_is_ref and result_is_ref) {
......@@ -6740,14 +6740,14 @@ pub const FuncGen = struct {
67406740 const array_ptr = self.buildAlloca(llvm_dest_ty);
67416741 const bitcast_ok = elem_ty.bitSize(target) == elem_ty.abiSize(target) * 8;
67426742 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);
67446744 const casted_ptr = self.builder.buildBitCast(array_ptr, llvm_vector_ty.pointerType(0), "");
67456745 const llvm_store = self.builder.buildStore(operand, casted_ptr);
67466746 llvm_store.setAlignment(inst_ty.abiAlignment(target));
67476747 } else {
67486748 // If the ABI size of the element type is not evenly divisible by size in bits;
67496749 // 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);
67516751 const llvm_u32 = self.context.intType(32);
67526752 const zero = llvm_usize.constNull();
67536753 const vector_len = operand_ty.arrayLen();
......@@ -6764,7 +6764,7 @@ pub const FuncGen = struct {
67646764 return array_ptr;
67656765 } else if (operand_ty.zigTypeTag() == .Array and inst_ty.zigTypeTag() == .Vector) {
67666766 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);
67686768 if (!operand_is_ref) {
67696769 return self.dg.todo("implement bitcast non-ref array to vector", .{});
67706770 }
......@@ -6781,7 +6781,7 @@ pub const FuncGen = struct {
67816781 } else {
67826782 // If the ABI size of the element type is not evenly divisible by size in bits;
67836783 // 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);
67856785 const llvm_u32 = self.context.intType(32);
67866786 const zero = llvm_usize.constNull();
67876787 const vector_len = operand_ty.arrayLen();
......@@ -6813,7 +6813,7 @@ pub const FuncGen = struct {
68136813 const alignment = @maximum(operand_ty.abiAlignment(target), inst_ty.abiAlignment(target));
68146814 const result_ptr = self.buildAlloca(llvm_dest_ty);
68156815 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);
68176817 const casted_ptr = self.builder.buildBitCast(result_ptr, operand_llvm_ty.pointerType(0), "");
68186818 const store_inst = self.builder.buildStore(operand, casted_ptr);
68196819 store_inst.setAlignment(alignment);
......@@ -6827,7 +6827,7 @@ pub const FuncGen = struct {
68276827 const alignment = @maximum(operand_ty.abiAlignment(target), inst_ty.abiAlignment(target));
68286828 const result_ptr = self.buildAlloca(llvm_dest_ty);
68296829 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);
68316831 const casted_ptr = self.builder.buildBitCast(result_ptr, operand_llvm_ty.pointerType(0), "");
68326832 const store_inst = self.builder.buildStore(operand, casted_ptr);
68336833 store_inst.setAlignment(alignment);
......@@ -6901,7 +6901,7 @@ pub const FuncGen = struct {
69016901 const pointee_type = ptr_ty.childType();
69026902 if (!pointee_type.isFnOrHasRuntimeBitsIgnoreComptime()) return self.dg.lowerPtrToVoid(ptr_ty);
69036903
6904 const pointee_llvm_ty = try self.dg.llvmType(pointee_type);
6904 const pointee_llvm_ty = try self.dg.lowerType(pointee_type);
69056905 const alloca_inst = self.buildAlloca(pointee_llvm_ty);
69066906 const target = self.dg.module.getTarget();
69076907 const alignment = ptr_ty.ptrAlignment(target);
......@@ -6915,7 +6915,7 @@ pub const FuncGen = struct {
69156915 const ret_ty = ptr_ty.childType();
69166916 if (!ret_ty.isFnOrHasRuntimeBitsIgnoreComptime()) return self.dg.lowerPtrToVoid(ptr_ty);
69176917 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);
69196919 const target = self.dg.module.getTarget();
69206920 const alloca_inst = self.buildAlloca(ret_llvm_ty);
69216921 alloca_inst.setAlignment(ptr_ty.ptrAlignment(target));
......@@ -6946,7 +6946,7 @@ pub const FuncGen = struct {
69466946 const dest_ptr_u8 = self.builder.buildBitCast(dest_ptr, ptr_u8_llvm_ty, "");
69476947 const fill_char = u8_llvm_ty.constInt(0xaa, .False);
69486948 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);
69506950 const len = usize_llvm_ty.constInt(operand_size, .False);
69516951 _ = self.builder.buildMemSet(dest_ptr_u8, fill_char, len, dest_ptr_align, ptr_ty.isVolatilePtr());
69526952 if (self.dg.module.comp.bin_file.options.valgrind) {
......@@ -6983,7 +6983,7 @@ pub const FuncGen = struct {
69836983 const llvm_fn = self.getIntrinsic("llvm.returnaddress", &.{});
69846984 const params = [_]*const llvm.Value{llvm_i32.constNull()};
69856985 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);
69876987 return self.builder.buildPtrToInt(ptr_val, llvm_usize, "");
69886988 }
69896989
......@@ -7001,7 +7001,7 @@ pub const FuncGen = struct {
70017001
70027002 const params = [_]*const llvm.Value{llvm_i32.constNull()};
70037003 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);
70057005 return self.builder.buildPtrToInt(ptr_val, llvm_usize, "");
70067006 }
70077007
......@@ -7046,7 +7046,7 @@ pub const FuncGen = struct {
70467046
70477047 var payload = self.builder.buildExtractValue(result, 0, "");
70487048 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), "");
70507050 }
70517051 const success_bit = self.builder.buildExtractValue(result, 1, "");
70527052
......@@ -7054,7 +7054,7 @@ pub const FuncGen = struct {
70547054 return self.builder.buildSelect(success_bit, payload.typeOf().constNull(), payload, "");
70557055 }
70567056
7057 const optional_llvm_ty = try self.dg.llvmType(optional_ty);
7057 const optional_llvm_ty = try self.dg.lowerType(optional_ty);
70587058 const non_null_bit = self.builder.buildNot(success_bit, "");
70597059 const partial = self.builder.buildInsertValue(optional_llvm_ty.getUndef(), payload, 0, "");
70607060 return self.builder.buildInsertValue(partial, non_null_bit, 1, "");
......@@ -7090,7 +7090,7 @@ pub const FuncGen = struct {
70907090 ordering,
70917091 single_threaded,
70927092 );
7093 const operand_llvm_ty = try self.dg.llvmType(operand_ty);
7093 const operand_llvm_ty = try self.dg.lowerType(operand_ty);
70947094 if (is_float) {
70957095 return self.builder.buildBitCast(uncasted_result, operand_llvm_ty, "");
70967096 } else {
......@@ -7103,7 +7103,7 @@ pub const FuncGen = struct {
71037103 }
71047104
71057105 // 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);
71077107 const casted_ptr = self.builder.buildBitCast(ptr, usize_llvm_ty.pointerType(0), "");
71087108 const casted_operand = self.builder.buildPtrToInt(operand, usize_llvm_ty, "");
71097109 const uncasted_result = self.builder.buildAtomicRmw(
......@@ -7113,7 +7113,7 @@ pub const FuncGen = struct {
71137113 ordering,
71147114 single_threaded,
71157115 );
7116 const operand_llvm_ty = try self.dg.llvmType(operand_ty);
7116 const operand_llvm_ty = try self.dg.lowerType(operand_ty);
71177117 return self.builder.buildIntToPtr(uncasted_result, operand_llvm_ty, "");
71187118 }
71197119
......@@ -7132,7 +7132,7 @@ pub const FuncGen = struct {
71327132 const casted_ptr = self.builder.buildBitCast(ptr, abi_ty.pointerType(0), "");
71337133 const load_inst = (try self.load(casted_ptr, ptr_ty)).?;
71347134 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), "");
71367136 }
71377137 const load_inst = (try self.load(ptr, ptr_ty)).?;
71387138 load_inst.setOrdering(ordering);
......@@ -7273,13 +7273,13 @@ pub const FuncGen = struct {
72737273 const operand = try self.resolveInst(ty_op.operand);
72747274
72757275 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);
72777277 const fn_val = self.getIntrinsic(llvm_fn_name, &.{operand_llvm_ty});
72787278
72797279 const params = [_]*const llvm.Value{ operand, llvm_i1.constNull() };
72807280 const wrong_size_result = self.builder.buildCall(fn_val, &params, params.len, .C, .Auto, "");
72817281 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);
72837283
72847284 const target = self.dg.module.getTarget();
72857285 const bits = operand_ty.intInfo(target).bits;
......@@ -7301,12 +7301,12 @@ pub const FuncGen = struct {
73017301 const operand = try self.resolveInst(ty_op.operand);
73027302
73037303 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);
73057305 const fn_val = self.getIntrinsic(llvm_fn_name, &.{operand_llvm_ty});
73067306
73077307 const wrong_size_result = self.builder.buildCall(fn_val, &params, params.len, .C, .Auto, "");
73087308 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);
73107310
73117311 const target = self.dg.module.getTarget();
73127312 const bits = operand_ty.intInfo(target).bits;
......@@ -7330,7 +7330,7 @@ pub const FuncGen = struct {
73307330 assert(bits % 8 == 0);
73317331
73327332 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);
73347334
73357335 if (bits % 16 == 8) {
73367336 // If not an even byte-multiple, we need zero-extend + shift-left 1 byte
......@@ -7364,7 +7364,7 @@ pub const FuncGen = struct {
73647364 const wrong_size_result = self.builder.buildCall(fn_val, &params, params.len, .C, .Auto, "");
73657365
73667366 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);
73687368 const result_bits = result_ty.intInfo(target).bits;
73697369 if (bits > result_bits) {
73707370 return self.builder.buildTrunc(wrong_size_result, result_llvm_ty, "");
......@@ -7407,14 +7407,14 @@ pub const FuncGen = struct {
74077407 }
74087408
74097409 const slice_ty = Type.initTag(.const_slice_u8_sentinel_0);
7410 const llvm_ret_ty = try self.dg.llvmType(slice_ty);
7411 const usize_llvm_ty = try self.dg.llvmType(Type.usize);
7410 const llvm_ret_ty = try self.dg.lowerType(slice_ty);
7411 const usize_llvm_ty = try self.dg.lowerType(Type.usize);
74127412 const target = self.dg.module.getTarget();
74137413 const slice_alignment = slice_ty.abiAlignment(target);
74147414
74157415 var int_tag_type_buffer: Type.Payload.Bits = undefined;
74167416 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)};
74187418
74197419 const fn_type = llvm.functionType(llvm_ret_ty, &param_types, param_types.len, .False);
74207420 const fn_val = self.dg.object.llvm_module.addFunction(llvm_fn_name, fn_type);
......@@ -7471,7 +7471,7 @@ pub const FuncGen = struct {
74717471 .base = .{ .tag = .enum_field_index },
74727472 .data = @intCast(u32, field_index),
74737473 };
7474 break :int try self.dg.genTypedValue(.{
7474 break :int try self.dg.lowerValue(.{
74757475 .ty = enum_ty,
74767476 .val = Value.initPayload(&tag_val_payload.base),
74777477 });
......@@ -7496,8 +7496,8 @@ pub const FuncGen = struct {
74967496
74977497 // Function signature: fn (anyerror) bool
74987498
7499 const ret_llvm_ty = try self.dg.llvmType(Type.bool);
7500 const anyerror_llvm_ty = try self.dg.llvmType(Type.anyerror);
7499 const ret_llvm_ty = try self.dg.lowerType(Type.bool);
7500 const anyerror_llvm_ty = try self.dg.lowerType(Type.anyerror);
75017501 const param_types = [_]*const llvm.Type{anyerror_llvm_ty};
75027502
75037503 const fn_type = llvm.functionType(ret_llvm_ty, &param_types, param_types.len, .False);
......@@ -7606,7 +7606,7 @@ pub const FuncGen = struct {
76067606 .Add => switch (scalar_ty.zigTypeTag()) {
76077607 .Int => return self.builder.buildAddReduce(operand),
76087608 .Float => {
7609 const scalar_llvm_ty = try self.dg.llvmType(scalar_ty);
7609 const scalar_llvm_ty = try self.dg.lowerType(scalar_ty);
76107610 const neutral_value = scalar_llvm_ty.constReal(-0.0);
76117611 return self.builder.buildFPAddReduce(neutral_value, operand);
76127612 },
......@@ -7615,7 +7615,7 @@ pub const FuncGen = struct {
76157615 .Mul => switch (scalar_ty.zigTypeTag()) {
76167616 .Int => return self.builder.buildMulReduce(operand),
76177617 .Float => {
7618 const scalar_llvm_ty = try self.dg.llvmType(scalar_ty);
7618 const scalar_llvm_ty = try self.dg.lowerType(scalar_ty);
76197619 const neutral_value = scalar_llvm_ty.constReal(1.0);
76207620 return self.builder.buildFPMulReduce(neutral_value, operand);
76217621 },
......@@ -7631,7 +7631,7 @@ pub const FuncGen = struct {
76317631 const result_ty = self.air.typeOfIndex(inst);
76327632 const len = @intCast(usize, result_ty.arrayLen());
76337633 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);
76357635 const target = self.dg.module.getTarget();
76367636
76377637 switch (result_ty.zigTypeTag()) {
......@@ -7719,7 +7719,7 @@ pub const FuncGen = struct {
77197719 .Array => {
77207720 assert(isByRef(result_ty));
77217721
7722 const llvm_usize = try self.dg.llvmType(Type.usize);
7722 const llvm_usize = try self.dg.lowerType(Type.usize);
77237723 const alloca_inst = self.buildAlloca(llvm_result_ty);
77247724 alloca_inst.setAlignment(result_ty.abiAlignment(target));
77257725
......@@ -7754,7 +7754,7 @@ pub const FuncGen = struct {
77547754 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
77557755 const extra = self.air.extraData(Air.UnionInit, ty_pl.payload).data;
77567756 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);
77587758 const target = self.dg.module.getTarget();
77597759 const layout = union_ty.unionGetLayout(target);
77607760 if (layout.payload_size == 0) {
......@@ -7774,8 +7774,8 @@ pub const FuncGen = struct {
77747774 const union_obj = union_ty.cast(Type.Payload.Union).?.data;
77757775 assert(union_obj.haveFieldTypes());
77767776 const field = union_obj.fields.values()[extra.field_index];
7777 const field_llvm_ty = try self.dg.llvmType(field.ty);
7778 const tag_llvm_ty = try self.dg.llvmType(union_obj.tag_ty);
7777 const field_llvm_ty = try self.dg.lowerType(field.ty);
7778 const tag_llvm_ty = try self.dg.lowerType(union_obj.tag_ty);
77797779 const field_size = field.ty.abiSize(target);
77807780 const field_align = field.normalAlignment(target);
77817781
......@@ -8011,7 +8011,7 @@ pub const FuncGen = struct {
80118011
80128012 const slice_ty = Type.initTag(.const_slice_u8_sentinel_0);
80138013 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);
80158015 const llvm_slice_ptr_ty = llvm_slice_ty.pointerType(0); // TODO: Address space
80168016
80178017 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 {
80758075 // out the relevant bits when accessing the pointee.
80768076 // Here we perform a bitcast because we want to use the host_size
80778077 // 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));
80798079 // TODO this can be removed if we change host_size to be bits instead
80808080 // of bytes.
80818081 return self.builder.buildBitCast(struct_ptr, result_llvm_ty, "");
......@@ -8090,7 +8090,7 @@ pub const FuncGen = struct {
80908090 // end of the struct. Treat our struct pointer as an array of two and get
80918091 // the index to the element at index `1` to get a pointer to the end of
80928092 // the struct.
8093 const llvm_usize = try self.dg.llvmType(Type.usize);
8093 const llvm_usize = try self.dg.lowerType(Type.usize);
80948094 const llvm_index = llvm_usize.constInt(1, .False);
80958095 const indices: [1]*const llvm.Value = .{llvm_index};
80968096 return self.builder.buildInBoundsGEP(struct_ptr, &indices, indices.len, "");
......@@ -8111,7 +8111,7 @@ pub const FuncGen = struct {
81118111 ) !?*const llvm.Value {
81128112 const union_obj = union_ty.cast(Type.Payload.Union).?.data;
81138113 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));
81158115 if (!field.ty.hasRuntimeBitsIgnoreComptime()) {
81168116 return null;
81178117 }
......@@ -8150,7 +8150,7 @@ pub const FuncGen = struct {
81508150 const ptr_volatile = llvm.Bool.fromBool(ptr_ty.isVolatilePtr());
81518151 if (info.host_size == 0) {
81528152 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);
81548154 const result_align = info.pointee_type.abiAlignment(target);
81558155 const max_align = @maximum(result_align, ptr_alignment);
81568156 const result_ptr = self.buildAlloca(elem_llvm_ty);
......@@ -8183,7 +8183,7 @@ pub const FuncGen = struct {
81838183 const elem_bits = @intCast(c_uint, ptr_ty.elemType().bitSize(target));
81848184 const shift_amt = containing_int.typeOf().constInt(info.bit_offset, .False);
81858185 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);
81878187
81888188 if (isByRef(info.pointee_type)) {
81898189 const result_align = info.pointee_type.abiAlignment(target);
......@@ -8625,7 +8625,7 @@ fn lowerFnRetTy(dg: *DeclGen, fn_info: Type.Payload.Function.Data) !*const llvm.
86258625 // anyerror return type instead, so that it can be coerced into a function
86268626 // pointer type which has anyerror as the return type.
86278627 if (fn_info.return_type.isError()) {
8628 return dg.llvmType(Type.anyerror);
8628 return dg.lowerType(Type.anyerror);
86298629 } else {
86308630 return dg.context.voidType();
86318631 }
......@@ -8636,7 +8636,7 @@ fn lowerFnRetTy(dg: *DeclGen, fn_info: Type.Payload.Function.Data) !*const llvm.
86368636 if (isByRef(fn_info.return_type)) {
86378637 return dg.context.voidType();
86388638 } else {
8639 return dg.llvmType(fn_info.return_type);
8639 return dg.lowerType(fn_info.return_type);
86408640 }
86418641 },
86428642 .C => {
......@@ -8657,24 +8657,24 @@ fn lowerFnRetTy(dg: *DeclGen, fn_info: Type.Payload.Function.Data) !*const llvm.
86578657 else => false,
86588658 };
86598659 switch (target.cpu.arch) {
8660 .mips, .mipsel => return dg.llvmType(fn_info.return_type),
8660 .mips, .mipsel => return dg.lowerType(fn_info.return_type),
86618661 .x86_64 => switch (target.os.tag) {
86628662 .windows => switch (x86_64_abi.classifyWindows(fn_info.return_type, target)) {
86638663 .integer => {
86648664 if (is_scalar) {
8665 return dg.llvmType(fn_info.return_type);
8665 return dg.lowerType(fn_info.return_type);
86668666 } else {
86678667 const abi_size = fn_info.return_type.abiSize(target);
86688668 return dg.context.intType(@intCast(c_uint, abi_size * 8));
86698669 }
86708670 },
86718671 .memory => return dg.context.voidType(),
8672 .sse => return dg.llvmType(fn_info.return_type),
8672 .sse => return dg.lowerType(fn_info.return_type),
86738673 else => unreachable,
86748674 },
86758675 else => {
86768676 if (is_scalar) {
8677 return dg.llvmType(fn_info.return_type);
8677 return dg.lowerType(fn_info.return_type);
86788678 }
86798679 const classes = x86_64_abi.classifySystemV(fn_info.return_type, target);
86808680 if (classes[0] == .memory) {
......@@ -8715,10 +8715,10 @@ fn lowerFnRetTy(dg: *DeclGen, fn_info: Type.Payload.Function.Data) !*const llvm.
87158715 },
87168716 },
87178717 // 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),
87198719 }
87208720 },
8721 else => return dg.llvmType(fn_info.return_type),
8721 else => return dg.lowerType(fn_info.return_type),
87228722 }
87238723}
87248724