| ... | ... | @@ -395,6 +395,27 @@ pub const Function = struct { |
| 395 | 395 | .shl, => try airBinBuiltinCall(f, inst, "shlw", .Bits), |
| 396 | 396 | .shl_exact => try airBinOp(f, inst, "<<", "shl", .None), |
| 397 | 397 | .not => try airNot (f, inst), |
| 398 | |
| 399 | .is_err => try airIsErr(f, inst, false, "!="), |
| 400 | .is_non_err => try airIsErr(f, inst, false, "=="), |
| 401 | .is_err_ptr => try airIsErr(f, inst, true, "!="), |
| 402 | .is_non_err_ptr => try airIsErr(f, inst, true, "=="), |
| 403 | |
| 404 | .is_null => try airIsNull(f, inst, "==", false), |
| 405 | .is_non_null => try airIsNull(f, inst, "!=", false), |
| 406 | .is_null_ptr => try airIsNull(f, inst, "==", true), |
| 407 | .is_non_null_ptr => try airIsNull(f, inst, "!=", true), |
| 408 | |
| 409 | .get_union_tag => try airGetUnionTag(f, inst), |
| 410 | .clz => try airUnBuiltinCall(f, inst, "clz", .Bits), |
| 411 | .ctz => try airUnBuiltinCall(f, inst, "ctz", .Bits), |
| 412 | .popcount => try airUnBuiltinCall(f, inst, "popcount", .Bits), |
| 413 | .byte_swap => try airUnBuiltinCall(f, inst, "byte_swap", .Bits), |
| 414 | .bit_reverse => try airUnBuiltinCall(f, inst, "bit_reverse", .Bits), |
| 415 | .tag_name => try airTagName(f, inst), |
| 416 | .error_name => try airErrorName(f, inst), |
| 417 | |
| 418 | .ptrtoint => try airPtrToInt(f, inst), |
| 398 | 419 | else => unreachable, |
| 399 | 420 | // zig fmt: on |
| 400 | 421 | } |
| ... | ... | @@ -422,6 +443,7 @@ pub const Function = struct { |
| 422 | 443 | try w.writeByte('.'); |
| 423 | 444 | return f.writeCValue(w, member, .Other); |
| 424 | 445 | }, |
| 446 | .inline_index => unreachable, // Use resolveInstNoInline |
| 425 | 447 | else => return f.object.dg.writeCValueMember(w, c_value, member), |
| 426 | 448 | } |
| 427 | 449 | } |
| ... | ... | @@ -2591,15 +2613,15 @@ fn genBody(f: *Function, body: []const Air.Inst.Index) error{ AnalysisFail, OutO |
| 2591 | 2613 | .optional_payload_ptr_set => try airOptionalPayloadPtrSet(f, inst), |
| 2592 | 2614 | .wrap_optional => try airWrapOptional(f, inst), |
| 2593 | 2615 | |
| 2594 | | .is_err => try airIsErr(f, inst, false, "!="), |
| 2595 | | .is_non_err => try airIsErr(f, inst, false, "=="), |
| 2596 | | .is_err_ptr => try airIsErr(f, inst, true, "!="), |
| 2597 | | .is_non_err_ptr => try airIsErr(f, inst, true, "=="), |
| 2616 | .is_err => CValue{ .inline_index = inst }, |
| 2617 | .is_non_err => CValue{ .inline_index = inst }, |
| 2618 | .is_err_ptr => CValue{ .inline_index = inst }, |
| 2619 | .is_non_err_ptr => CValue{ .inline_index = inst }, |
| 2598 | 2620 | |
| 2599 | | .is_null => try airIsNull(f, inst, "==", false), |
| 2600 | | .is_non_null => try airIsNull(f, inst, "!=", false), |
| 2601 | | .is_null_ptr => try airIsNull(f, inst, "==", true), |
| 2602 | | .is_non_null_ptr => try airIsNull(f, inst, "!=", true), |
| 2621 | .is_null => CValue{ .inline_index = inst }, |
| 2622 | .is_non_null => CValue{ .inline_index = inst }, |
| 2623 | .is_null_ptr => CValue{ .inline_index = inst }, |
| 2624 | .is_non_null_ptr => CValue{ .inline_index = inst }, |
| 2603 | 2625 | |
| 2604 | 2626 | .alloc => try airAlloc(f, inst), |
| 2605 | 2627 | .ret_ptr => try airRetPtr(f, inst), |
| ... | ... | @@ -2627,14 +2649,14 @@ fn genBody(f: *Function, body: []const Air.Inst.Index) error{ AnalysisFail, OutO |
| 2627 | 2649 | .memset => try airMemset(f, inst), |
| 2628 | 2650 | .memcpy => try airMemcpy(f, inst), |
| 2629 | 2651 | .set_union_tag => try airSetUnionTag(f, inst), |
| 2630 | | .get_union_tag => try airGetUnionTag(f, inst), |
| 2631 | | .clz => try airUnBuiltinCall(f, inst, "clz", .Bits), |
| 2632 | | .ctz => try airUnBuiltinCall(f, inst, "ctz", .Bits), |
| 2633 | | .popcount => try airUnBuiltinCall(f, inst, "popcount", .Bits), |
| 2634 | | .byte_swap => try airUnBuiltinCall(f, inst, "byte_swap", .Bits), |
| 2635 | | .bit_reverse => try airUnBuiltinCall(f, inst, "bit_reverse", .Bits), |
| 2636 | | .tag_name => try airTagName(f, inst), |
| 2637 | | .error_name => try airErrorName(f, inst), |
| 2652 | .get_union_tag => CValue{ .inline_index = inst }, |
| 2653 | .clz => CValue{ .inline_index = inst }, |
| 2654 | .ctz => CValue{ .inline_index = inst }, |
| 2655 | .popcount => CValue{ .inline_index = inst }, |
| 2656 | .byte_swap => CValue{ .inline_index = inst }, |
| 2657 | .bit_reverse => CValue{ .inline_index = inst }, |
| 2658 | .tag_name => CValue{ .inline_index = inst }, |
| 2659 | .error_name => CValue{ .inline_index = inst }, |
| 2638 | 2660 | .splat => try airSplat(f, inst), |
| 2639 | 2661 | .select => try airSelect(f, inst), |
| 2640 | 2662 | .shuffle => try airShuffle(f, inst), |
| ... | ... | @@ -2670,7 +2692,7 @@ fn genBody(f: *Function, body: []const Air.Inst.Index) error{ AnalysisFail, OutO |
| 2670 | 2692 | .fpext, |
| 2671 | 2693 | => try airFloatCast(f, inst), |
| 2672 | 2694 | |
| 2673 | | .ptrtoint => try airPtrToInt(f, inst), |
| 2695 | .ptrtoint => CValue{ .inline_index = inst }, |
| 2674 | 2696 | |
| 2675 | 2697 | .atomic_store_unordered => try airAtomicStore(f, inst, toMemoryOrder(.Unordered)), |
| 2676 | 2698 | .atomic_store_monotonic => try airAtomicStore(f, inst, toMemoryOrder(.Monotonic)), |
| ... | ... | @@ -2754,7 +2776,7 @@ fn airSliceField(f: *Function, inst: Air.Inst.Index, is_ptr: bool, field_name: [ |
| 2754 | 2776 | |
| 2755 | 2777 | const inst_ty = f.air.typeOfIndex(inst); |
| 2756 | 2778 | const ty_op = f.air.instructions.items(.data)[inst].ty_op; |
| 2757 | | const operand = try f.resolveInst(ty_op.operand); |
| 2779 | const operand = try f.resolveInstNoInline(ty_op.operand); |
| 2758 | 2780 | const writer = f.object.writer(); |
| 2759 | 2781 | const local = try f.allocLocal(inst_ty, .Const); |
| 2760 | 2782 | try writer.writeAll(" = "); |
| ... | ... | @@ -4234,16 +4256,11 @@ fn airIsNull( |
| 4234 | 4256 | inst: Air.Inst.Index, |
| 4235 | 4257 | operator: []const u8, |
| 4236 | 4258 | is_ptr: bool, |
| 4237 | | ) !CValue { |
| 4238 | | if (f.liveness.isUnused(inst)) |
| 4239 | | return CValue.none; |
| 4240 | | |
| 4259 | ) !void { |
| 4241 | 4260 | const un_op = f.air.instructions.items(.data)[inst].un_op; |
| 4242 | 4261 | const writer = f.object.writer(); |
| 4243 | 4262 | const operand = try f.resolveInst(un_op); |
| 4244 | 4263 | |
| 4245 | | const local = try f.allocLocal(Type.initTag(.bool), .Const); |
| 4246 | | try writer.writeAll(" = "); |
| 4247 | 4264 | try if (is_ptr) f.writeCValueDeref(writer, operand) else f.writeCValue(writer, operand, .Other); |
| 4248 | 4265 | |
| 4249 | 4266 | const operand_ty = f.air.typeOf(un_op); |
| ... | ... | @@ -4271,8 +4288,6 @@ fn airIsNull( |
| 4271 | 4288 | try writer.writeAll(operator); |
| 4272 | 4289 | try writer.writeByte(' '); |
| 4273 | 4290 | try f.object.dg.renderValue(writer, rhs.ty, rhs.val, .Other); |
| 4274 | | try writer.writeAll(";\n"); |
| 4275 | | return local; |
| 4276 | 4291 | } |
| 4277 | 4292 | |
| 4278 | 4293 | fn airOptionalPayload(f: *Function, inst: Air.Inst.Index) !CValue { |
| ... | ... | @@ -4842,21 +4857,15 @@ fn airWrapErrUnionPay(f: *Function, inst: Air.Inst.Index) !CValue { |
| 4842 | 4857 | return local; |
| 4843 | 4858 | } |
| 4844 | 4859 | |
| 4845 | | fn airIsErr(f: *Function, inst: Air.Inst.Index, is_ptr: bool, operator: []const u8) !CValue { |
| 4846 | | if (f.liveness.isUnused(inst)) |
| 4847 | | return CValue.none; |
| 4848 | | |
| 4860 | fn airIsErr(f: *Function, inst: Air.Inst.Index, is_ptr: bool, operator: []const u8) !void { |
| 4849 | 4861 | const un_op = f.air.instructions.items(.data)[inst].un_op; |
| 4850 | 4862 | const writer = f.object.writer(); |
| 4851 | 4863 | const operand = try f.resolveInst(un_op); |
| 4852 | 4864 | const operand_ty = f.air.typeOf(un_op); |
| 4853 | | const local = try f.allocLocal(Type.initTag(.bool), .Const); |
| 4854 | 4865 | const err_union_ty = if (is_ptr) operand_ty.childType() else operand_ty; |
| 4855 | 4866 | const payload_ty = err_union_ty.errorUnionPayload(); |
| 4856 | 4867 | const error_ty = err_union_ty.errorUnionSet(); |
| 4857 | 4868 | |
| 4858 | | try writer.writeAll(" = "); |
| 4859 | | |
| 4860 | 4869 | if (!error_ty.errorSetIsEmpty()) |
| 4861 | 4870 | if (payload_ty.hasRuntimeBits()) |
| 4862 | 4871 | if (is_ptr) |
| ... | ... | @@ -4871,8 +4880,6 @@ fn airIsErr(f: *Function, inst: Air.Inst.Index, is_ptr: bool, operator: []const |
| 4871 | 4880 | try writer.writeAll(operator); |
| 4872 | 4881 | try writer.writeByte(' '); |
| 4873 | 4882 | try f.object.dg.renderValue(writer, error_ty, Value.zero, .Other); |
| 4874 | | try writer.writeAll(";\n"); |
| 4875 | | return local; |
| 4876 | 4883 | } |
| 4877 | 4884 | |
| 4878 | 4885 | fn airArrayToSlice(f: *Function, inst: Air.Inst.Index) !CValue { |
| ... | ... | @@ -4946,21 +4953,16 @@ fn airFloatCast(f: *Function, inst: Air.Inst.Index) !CValue { |
| 4946 | 4953 | return local; |
| 4947 | 4954 | } |
| 4948 | 4955 | |
| 4949 | | fn airPtrToInt(f: *Function, inst: Air.Inst.Index) !CValue { |
| 4950 | | if (f.liveness.isUnused(inst)) return CValue.none; |
| 4951 | | |
| 4956 | fn airPtrToInt(f: *Function, inst: Air.Inst.Index) !void { |
| 4952 | 4957 | const inst_ty = f.air.typeOfIndex(inst); |
| 4953 | | const local = try f.allocLocal(inst_ty, .Const); |
| 4954 | 4958 | const un_op = f.air.instructions.items(.data)[inst].un_op; |
| 4955 | 4959 | const writer = f.object.writer(); |
| 4956 | 4960 | const operand = try f.resolveInst(un_op); |
| 4957 | 4961 | |
| 4958 | | try writer.writeAll(" = ("); |
| 4962 | try writer.writeAll("("); |
| 4959 | 4963 | try f.renderTypecast(writer, inst_ty); |
| 4960 | 4964 | try writer.writeByte(')'); |
| 4961 | 4965 | try f.writeCValue(writer, operand, .Other); |
| 4962 | | try writer.writeAll(";\n"); |
| 4963 | | return local; |
| 4964 | 4966 | } |
| 4965 | 4967 | |
| 4966 | 4968 | fn airUnBuiltinCall( |
| ... | ... | @@ -4968,24 +4970,19 @@ fn airUnBuiltinCall( |
| 4968 | 4970 | inst: Air.Inst.Index, |
| 4969 | 4971 | operation: []const u8, |
| 4970 | 4972 | info: BuiltinInfo, |
| 4971 | | ) !CValue { |
| 4972 | | if (f.liveness.isUnused(inst)) return CValue.none; |
| 4973 | | |
| 4974 | | const inst_ty = f.air.typeOfIndex(inst); |
| 4973 | ) !void { |
| 4975 | 4974 | const operand = f.air.instructions.items(.data)[inst].ty_op.operand; |
| 4976 | 4975 | const operand_ty = f.air.typeOf(operand); |
| 4977 | 4976 | |
| 4978 | | const local = try f.allocLocal(inst_ty, .Const); |
| 4979 | 4977 | const writer = f.object.writer(); |
| 4980 | | try writer.writeAll(" = zig_"); |
| 4978 | try writer.writeAll("zig_"); |
| 4981 | 4979 | try writer.writeAll(operation); |
| 4982 | 4980 | try writer.writeByte('_'); |
| 4983 | 4981 | try f.object.dg.renderTypeForBuiltinFnName(writer, operand_ty); |
| 4984 | 4982 | try writer.writeByte('('); |
| 4985 | 4983 | try f.writeCValue(writer, try f.resolveInst(operand), .FunctionArgument); |
| 4986 | 4984 | try f.object.dg.renderBuiltinInfo(writer, operand_ty, info); |
| 4987 | | try writer.writeAll(");\n"); |
| 4988 | | return local; |
| 4985 | try writer.writeAll(")"); |
| 4989 | 4986 | } |
| 4990 | 4987 | |
| 4991 | 4988 | fn airBinBuiltinCall( |
| ... | ... | @@ -5258,12 +5255,7 @@ fn airSetUnionTag(f: *Function, inst: Air.Inst.Index) !CValue { |
| 5258 | 5255 | return CValue.none; |
| 5259 | 5256 | } |
| 5260 | 5257 | |
| 5261 | | fn airGetUnionTag(f: *Function, inst: Air.Inst.Index) !CValue { |
| 5262 | | if (f.liveness.isUnused(inst)) |
| 5263 | | return CValue.none; |
| 5264 | | |
| 5265 | | const inst_ty = f.air.typeOfIndex(inst); |
| 5266 | | const local = try f.allocLocal(inst_ty, .Const); |
| 5258 | fn airGetUnionTag(f: *Function, inst: Air.Inst.Index) !void { |
| 5267 | 5259 | const ty_op = f.air.instructions.items(.data)[inst].ty_op; |
| 5268 | 5260 | const un_ty = f.air.typeOf(ty_op.operand); |
| 5269 | 5261 | const writer = f.object.writer(); |
| ... | ... | @@ -5271,44 +5263,31 @@ fn airGetUnionTag(f: *Function, inst: Air.Inst.Index) !CValue { |
| 5271 | 5263 | |
| 5272 | 5264 | const target = f.object.dg.module.getTarget(); |
| 5273 | 5265 | const layout = un_ty.unionGetLayout(target); |
| 5274 | | if (layout.tag_size == 0) return CValue.none; |
| 5266 | assert(layout.tag_size != 0); |
| 5275 | 5267 | |
| 5276 | | try writer.writeAll(" = "); |
| 5277 | 5268 | try f.writeCValue(writer, operand, .Other); |
| 5278 | | try writer.writeAll(".tag;\n"); |
| 5279 | | return local; |
| 5269 | try writer.writeAll(".tag"); |
| 5280 | 5270 | } |
| 5281 | 5271 | |
| 5282 | | fn airTagName(f: *Function, inst: Air.Inst.Index) !CValue { |
| 5283 | | if (f.liveness.isUnused(inst)) return CValue.none; |
| 5284 | | |
| 5272 | fn airTagName(f: *Function, inst: Air.Inst.Index) !void { |
| 5285 | 5273 | const un_op = f.air.instructions.items(.data)[inst].un_op; |
| 5286 | | const inst_ty = f.air.typeOfIndex(inst); |
| 5287 | 5274 | const enum_ty = f.air.typeOf(un_op); |
| 5288 | 5275 | const operand = try f.resolveInst(un_op); |
| 5289 | 5276 | |
| 5290 | 5277 | const writer = f.object.writer(); |
| 5291 | | const local = try f.allocLocal(inst_ty, .Const); |
| 5292 | | try writer.print(" = {s}(", .{try f.object.dg.getTagNameFn(enum_ty)}); |
| 5278 | try writer.print("{s}(", .{try f.object.dg.getTagNameFn(enum_ty)}); |
| 5293 | 5279 | try f.writeCValue(writer, operand, .Other); |
| 5294 | | try writer.writeAll(");\n"); |
| 5295 | | |
| 5296 | | return local; |
| 5280 | try writer.writeAll(")"); |
| 5297 | 5281 | } |
| 5298 | 5282 | |
| 5299 | | fn airErrorName(f: *Function, inst: Air.Inst.Index) !CValue { |
| 5300 | | if (f.liveness.isUnused(inst)) return CValue.none; |
| 5301 | | |
| 5283 | fn airErrorName(f: *Function, inst: Air.Inst.Index) !void { |
| 5302 | 5284 | const un_op = f.air.instructions.items(.data)[inst].un_op; |
| 5303 | 5285 | const writer = f.object.writer(); |
| 5304 | | const inst_ty = f.air.typeOfIndex(inst); |
| 5305 | 5286 | const operand = try f.resolveInst(un_op); |
| 5306 | | const local = try f.allocLocal(inst_ty, .Const); |
| 5307 | 5287 | |
| 5308 | | try writer.writeAll(" = zig_errorName["); |
| 5288 | try writer.writeAll("zig_errorName["); |
| 5309 | 5289 | try f.writeCValue(writer, operand, .Other); |
| 5310 | | try writer.writeAll("];\n"); |
| 5311 | | return local; |
| 5290 | try writer.writeAll("]"); |
| 5312 | 5291 | } |
| 5313 | 5292 | |
| 5314 | 5293 | fn airSplat(f: *Function, inst: Air.Inst.Index) !CValue { |