authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2023-08-07 04:23:02-04:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2023-08-08 21:32:50-04:00
loge1efd4d3c22cad89ed89ea152c92b1c3260ddb8a
tree84acb00487739e068c9603263bc243b601b5de93
parent5b79f08ee82a48d84146706faf2229e7c298340d

Builder: simplify intrinsic table

This format removes back-references allowing it to be parsed in a single pass. It also reduces the number of kinds, simplifying the code.

1 files changed, 139 insertions(+), 56 deletions(-)

src/codegen/llvm/Builder.zig+139-56
......@@ -2462,7 +2462,8 @@ pub const Intrinsic = enum {
24622462 @"wasm.memory.grow",
24632463
24642464 const Signature = struct {
2465 params: []const Parameter = &.{},
2465 ret_len: u8,
2466 params: []const Parameter,
24662467 attrs: []const Attribute = &.{},
24672468
24682469 const Parameter = struct {
......@@ -2471,33 +2472,37 @@ pub const Intrinsic = enum {
24712472
24722473 const Kind = union(enum) {
24732474 type: Type,
2475 change_scalar: struct {
2476 index: u8,
2477 scalar: Type,
2478 },
24742479 overloaded,
2475 overloaded_tuple: u8,
24762480 matches: u8,
2477 matches_tuple: packed struct { param: u4, field: u4 },
2478 matches_with_overflow: u8,
24792481 };
24802482 };
24812483 };
24822484
2483 const signatures = std.enums.EnumArray(Intrinsic, Signature).initDefault(.{}, .{
2485 const signatures = std.enums.EnumArray(Intrinsic, Signature).initDefault(.{
2486 .ret_len = 0,
2487 .params = &.{},
2488 }, .{
24842489 .va_start = .{
2490 .ret_len = 0,
24852491 .params = &.{
2486 .{ .kind = .{ .type = .void } },
24872492 .{ .kind = .{ .type = .ptr } },
24882493 },
24892494 .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .willreturn },
24902495 },
24912496 .va_end = .{
2497 .ret_len = 0,
24922498 .params = &.{
2493 .{ .kind = .{ .type = .void } },
24942499 .{ .kind = .{ .type = .ptr } },
24952500 },
24962501 .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .willreturn },
24972502 },
24982503 .va_copy = .{
2504 .ret_len = 0,
24992505 .params = &.{
2500 .{ .kind = .{ .type = .void } },
25012506 .{ .kind = .{ .type = .ptr } },
25022507 .{ .kind = .{ .type = .ptr } },
25032508 },
......@@ -2505,6 +2510,7 @@ pub const Intrinsic = enum {
25052510 },
25062511
25072512 .returnaddress = .{
2513 .ret_len = 1,
25082514 .params = &.{
25092515 .{ .kind = .{ .type = .ptr } },
25102516 .{ .kind = .{ .type = .i32 }, .attrs = &.{.immarg} },
......@@ -2512,18 +2518,21 @@ pub const Intrinsic = enum {
25122518 .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .willreturn, .{ .memory = Attribute.Memory.all(.none) } },
25132519 },
25142520 .addressofreturnaddress = .{
2521 .ret_len = 1,
25152522 .params = &.{
25162523 .{ .kind = .overloaded },
25172524 },
25182525 .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .willreturn, .{ .memory = Attribute.Memory.all(.none) } },
25192526 },
25202527 .sponentry = .{
2528 .ret_len = 1,
25212529 .params = &.{
25222530 .{ .kind = .overloaded },
25232531 },
25242532 .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .willreturn, .{ .memory = Attribute.Memory.all(.none) } },
25252533 },
25262534 .frameaddress = .{
2535 .ret_len = 1,
25272536 .params = &.{
25282537 .{ .kind = .overloaded },
25292538 .{ .kind = .{ .type = .i32 }, .attrs = &.{.immarg} },
......@@ -2531,8 +2540,8 @@ pub const Intrinsic = enum {
25312540 .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .willreturn, .{ .memory = Attribute.Memory.all(.none) } },
25322541 },
25332542 .prefetch = .{
2543 .ret_len = 0,
25342544 .params = &.{
2535 .{ .kind = .{ .type = .void } },
25362545 .{ .kind = .overloaded, .attrs = &.{ .nocapture, .readonly } },
25372546 .{ .kind = .{ .type = .i32 }, .attrs = &.{.immarg} },
25382547 .{ .kind = .{ .type = .i32 }, .attrs = &.{.immarg} },
......@@ -2541,6 +2550,7 @@ pub const Intrinsic = enum {
25412550 .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .willreturn, .{ .memory = Attribute.Memory.all(.readwrite) } },
25422551 },
25432552 .@"thread.pointer" = .{
2553 .ret_len = 1,
25442554 .params = &.{
25452555 .{ .kind = .{ .type = .ptr } },
25462556 },
......@@ -2548,6 +2558,7 @@ pub const Intrinsic = enum {
25482558 },
25492559
25502560 .abs = .{
2561 .ret_len = 1,
25512562 .params = &.{
25522563 .{ .kind = .overloaded },
25532564 .{ .kind = .{ .matches = 0 } },
......@@ -2556,6 +2567,7 @@ pub const Intrinsic = enum {
25562567 .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = Attribute.Memory.all(.none) } },
25572568 },
25582569 .smax = .{
2570 .ret_len = 1,
25592571 .params = &.{
25602572 .{ .kind = .overloaded },
25612573 .{ .kind = .{ .matches = 0 } },
......@@ -2564,6 +2576,7 @@ pub const Intrinsic = enum {
25642576 .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = Attribute.Memory.all(.none) } },
25652577 },
25662578 .smin = .{
2579 .ret_len = 1,
25672580 .params = &.{
25682581 .{ .kind = .overloaded },
25692582 .{ .kind = .{ .matches = 0 } },
......@@ -2572,6 +2585,7 @@ pub const Intrinsic = enum {
25722585 .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = Attribute.Memory.all(.none) } },
25732586 },
25742587 .umax = .{
2588 .ret_len = 1,
25752589 .params = &.{
25762590 .{ .kind = .overloaded },
25772591 .{ .kind = .{ .matches = 0 } },
......@@ -2580,6 +2594,7 @@ pub const Intrinsic = enum {
25802594 .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = Attribute.Memory.all(.none) } },
25812595 },
25822596 .umin = .{
2597 .ret_len = 1,
25832598 .params = &.{
25842599 .{ .kind = .overloaded },
25852600 .{ .kind = .{ .matches = 0 } },
......@@ -2588,6 +2603,7 @@ pub const Intrinsic = enum {
25882603 .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = Attribute.Memory.all(.none) } },
25892604 },
25902605 .sqrt = .{
2606 .ret_len = 1,
25912607 .params = &.{
25922608 .{ .kind = .overloaded },
25932609 .{ .kind = .{ .matches = 0 } },
......@@ -2595,6 +2611,7 @@ pub const Intrinsic = enum {
25952611 .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = Attribute.Memory.all(.none) } },
25962612 },
25972613 .powi = .{
2614 .ret_len = 1,
25982615 .params = &.{
25992616 .{ .kind = .overloaded },
26002617 .{ .kind = .{ .matches = 0 } },
......@@ -2603,6 +2620,7 @@ pub const Intrinsic = enum {
26032620 .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = Attribute.Memory.all(.none) } },
26042621 },
26052622 .sin = .{
2623 .ret_len = 1,
26062624 .params = &.{
26072625 .{ .kind = .overloaded },
26082626 .{ .kind = .{ .matches = 0 } },
......@@ -2610,6 +2628,7 @@ pub const Intrinsic = enum {
26102628 .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = Attribute.Memory.all(.none) } },
26112629 },
26122630 .cos = .{
2631 .ret_len = 1,
26132632 .params = &.{
26142633 .{ .kind = .overloaded },
26152634 .{ .kind = .{ .matches = 0 } },
......@@ -2617,6 +2636,7 @@ pub const Intrinsic = enum {
26172636 .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = Attribute.Memory.all(.none) } },
26182637 },
26192638 .pow = .{
2639 .ret_len = 1,
26202640 .params = &.{
26212641 .{ .kind = .overloaded },
26222642 .{ .kind = .{ .matches = 0 } },
......@@ -2625,6 +2645,7 @@ pub const Intrinsic = enum {
26252645 .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = Attribute.Memory.all(.none) } },
26262646 },
26272647 .exp = .{
2648 .ret_len = 1,
26282649 .params = &.{
26292650 .{ .kind = .overloaded },
26302651 .{ .kind = .{ .matches = 0 } },
......@@ -2632,6 +2653,7 @@ pub const Intrinsic = enum {
26322653 .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = Attribute.Memory.all(.none) } },
26332654 },
26342655 .exp2 = .{
2656 .ret_len = 1,
26352657 .params = &.{
26362658 .{ .kind = .overloaded },
26372659 .{ .kind = .{ .matches = 0 } },
......@@ -2639,6 +2661,7 @@ pub const Intrinsic = enum {
26392661 .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = Attribute.Memory.all(.none) } },
26402662 },
26412663 .ldexp = .{
2664 .ret_len = 1,
26422665 .params = &.{
26432666 .{ .kind = .overloaded },
26442667 .{ .kind = .{ .matches = 0 } },
......@@ -2647,13 +2670,16 @@ pub const Intrinsic = enum {
26472670 .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = Attribute.Memory.all(.none) } },
26482671 },
26492672 .frexp = .{
2673 .ret_len = 2,
26502674 .params = &.{
2651 .{ .kind = .{ .overloaded_tuple = 2 } },
2652 .{ .kind = .{ .matches_tuple = .{ .param = 0, .field = 0 } } },
2675 .{ .kind = .overloaded },
2676 .{ .kind = .overloaded },
2677 .{ .kind = .{ .matches = 0 } },
26532678 },
26542679 .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = Attribute.Memory.all(.none) } },
26552680 },
26562681 .log = .{
2682 .ret_len = 1,
26572683 .params = &.{
26582684 .{ .kind = .overloaded },
26592685 .{ .kind = .{ .matches = 0 } },
......@@ -2661,6 +2687,7 @@ pub const Intrinsic = enum {
26612687 .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = Attribute.Memory.all(.none) } },
26622688 },
26632689 .log10 = .{
2690 .ret_len = 1,
26642691 .params = &.{
26652692 .{ .kind = .overloaded },
26662693 .{ .kind = .{ .matches = 0 } },
......@@ -2668,6 +2695,7 @@ pub const Intrinsic = enum {
26682695 .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = Attribute.Memory.all(.none) } },
26692696 },
26702697 .log2 = .{
2698 .ret_len = 1,
26712699 .params = &.{
26722700 .{ .kind = .overloaded },
26732701 .{ .kind = .{ .matches = 0 } },
......@@ -2675,6 +2703,7 @@ pub const Intrinsic = enum {
26752703 .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = Attribute.Memory.all(.none) } },
26762704 },
26772705 .fma = .{
2706 .ret_len = 1,
26782707 .params = &.{
26792708 .{ .kind = .overloaded },
26802709 .{ .kind = .{ .matches = 0 } },
......@@ -2684,6 +2713,7 @@ pub const Intrinsic = enum {
26842713 .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = Attribute.Memory.all(.none) } },
26852714 },
26862715 .fabs = .{
2716 .ret_len = 1,
26872717 .params = &.{
26882718 .{ .kind = .overloaded },
26892719 .{ .kind = .{ .matches = 0 } },
......@@ -2691,6 +2721,7 @@ pub const Intrinsic = enum {
26912721 .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = Attribute.Memory.all(.none) } },
26922722 },
26932723 .minnum = .{
2724 .ret_len = 1,
26942725 .params = &.{
26952726 .{ .kind = .overloaded },
26962727 .{ .kind = .{ .matches = 0 } },
......@@ -2699,6 +2730,7 @@ pub const Intrinsic = enum {
26992730 .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = Attribute.Memory.all(.none) } },
27002731 },
27012732 .maxnum = .{
2733 .ret_len = 1,
27022734 .params = &.{
27032735 .{ .kind = .overloaded },
27042736 .{ .kind = .{ .matches = 0 } },
......@@ -2707,6 +2739,7 @@ pub const Intrinsic = enum {
27072739 .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = Attribute.Memory.all(.none) } },
27082740 },
27092741 .minimum = .{
2742 .ret_len = 1,
27102743 .params = &.{
27112744 .{ .kind = .overloaded },
27122745 .{ .kind = .{ .matches = 0 } },
......@@ -2715,6 +2748,7 @@ pub const Intrinsic = enum {
27152748 .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = Attribute.Memory.all(.none) } },
27162749 },
27172750 .maximum = .{
2751 .ret_len = 1,
27182752 .params = &.{
27192753 .{ .kind = .overloaded },
27202754 .{ .kind = .{ .matches = 0 } },
......@@ -2723,6 +2757,7 @@ pub const Intrinsic = enum {
27232757 .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = Attribute.Memory.all(.none) } },
27242758 },
27252759 .copysign = .{
2760 .ret_len = 1,
27262761 .params = &.{
27272762 .{ .kind = .overloaded },
27282763 .{ .kind = .{ .matches = 0 } },
......@@ -2731,6 +2766,7 @@ pub const Intrinsic = enum {
27312766 .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = Attribute.Memory.all(.none) } },
27322767 },
27332768 .floor = .{
2769 .ret_len = 1,
27342770 .params = &.{
27352771 .{ .kind = .overloaded },
27362772 .{ .kind = .{ .matches = 0 } },
......@@ -2738,6 +2774,7 @@ pub const Intrinsic = enum {
27382774 .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = Attribute.Memory.all(.none) } },
27392775 },
27402776 .ceil = .{
2777 .ret_len = 1,
27412778 .params = &.{
27422779 .{ .kind = .overloaded },
27432780 .{ .kind = .{ .matches = 0 } },
......@@ -2745,6 +2782,7 @@ pub const Intrinsic = enum {
27452782 .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = Attribute.Memory.all(.none) } },
27462783 },
27472784 .trunc = .{
2785 .ret_len = 1,
27482786 .params = &.{
27492787 .{ .kind = .overloaded },
27502788 .{ .kind = .{ .matches = 0 } },
......@@ -2752,6 +2790,7 @@ pub const Intrinsic = enum {
27522790 .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = Attribute.Memory.all(.none) } },
27532791 },
27542792 .rint = .{
2793 .ret_len = 1,
27552794 .params = &.{
27562795 .{ .kind = .overloaded },
27572796 .{ .kind = .{ .matches = 0 } },
......@@ -2759,6 +2798,7 @@ pub const Intrinsic = enum {
27592798 .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = Attribute.Memory.all(.none) } },
27602799 },
27612800 .nearbyint = .{
2801 .ret_len = 1,
27622802 .params = &.{
27632803 .{ .kind = .overloaded },
27642804 .{ .kind = .{ .matches = 0 } },
......@@ -2766,6 +2806,7 @@ pub const Intrinsic = enum {
27662806 .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = Attribute.Memory.all(.none) } },
27672807 },
27682808 .round = .{
2809 .ret_len = 1,
27692810 .params = &.{
27702811 .{ .kind = .overloaded },
27712812 .{ .kind = .{ .matches = 0 } },
......@@ -2773,6 +2814,7 @@ pub const Intrinsic = enum {
27732814 .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = Attribute.Memory.all(.none) } },
27742815 },
27752816 .roundeven = .{
2817 .ret_len = 1,
27762818 .params = &.{
27772819 .{ .kind = .overloaded },
27782820 .{ .kind = .{ .matches = 0 } },
......@@ -2780,6 +2822,7 @@ pub const Intrinsic = enum {
27802822 .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = Attribute.Memory.all(.none) } },
27812823 },
27822824 .lround = .{
2825 .ret_len = 1,
27832826 .params = &.{
27842827 .{ .kind = .overloaded },
27852828 .{ .kind = .overloaded },
......@@ -2787,6 +2830,7 @@ pub const Intrinsic = enum {
27872830 .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = Attribute.Memory.all(.none) } },
27882831 },
27892832 .llround = .{
2833 .ret_len = 1,
27902834 .params = &.{
27912835 .{ .kind = .overloaded },
27922836 .{ .kind = .overloaded },
......@@ -2794,6 +2838,7 @@ pub const Intrinsic = enum {
27942838 .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = Attribute.Memory.all(.none) } },
27952839 },
27962840 .lrint = .{
2841 .ret_len = 1,
27972842 .params = &.{
27982843 .{ .kind = .overloaded },
27992844 .{ .kind = .overloaded },
......@@ -2801,6 +2846,7 @@ pub const Intrinsic = enum {
28012846 .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = Attribute.Memory.all(.none) } },
28022847 },
28032848 .llrint = .{
2849 .ret_len = 1,
28042850 .params = &.{
28052851 .{ .kind = .overloaded },
28062852 .{ .kind = .overloaded },
......@@ -2809,6 +2855,7 @@ pub const Intrinsic = enum {
28092855 },
28102856
28112857 .bitreverse = .{
2858 .ret_len = 1,
28122859 .params = &.{
28132860 .{ .kind = .overloaded },
28142861 .{ .kind = .{ .matches = 0 } },
......@@ -2816,6 +2863,7 @@ pub const Intrinsic = enum {
28162863 .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = Attribute.Memory.all(.none) } },
28172864 },
28182865 .bswap = .{
2866 .ret_len = 1,
28192867 .params = &.{
28202868 .{ .kind = .overloaded },
28212869 .{ .kind = .{ .matches = 0 } },
......@@ -2823,6 +2871,7 @@ pub const Intrinsic = enum {
28232871 .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = Attribute.Memory.all(.none) } },
28242872 },
28252873 .ctpop = .{
2874 .ret_len = 1,
28262875 .params = &.{
28272876 .{ .kind = .overloaded },
28282877 .{ .kind = .{ .matches = 0 } },
......@@ -2830,6 +2879,7 @@ pub const Intrinsic = enum {
28302879 .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = Attribute.Memory.all(.none) } },
28312880 },
28322881 .ctlz = .{
2882 .ret_len = 1,
28332883 .params = &.{
28342884 .{ .kind = .overloaded },
28352885 .{ .kind = .{ .matches = 0 } },
......@@ -2838,6 +2888,7 @@ pub const Intrinsic = enum {
28382888 .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = Attribute.Memory.all(.none) } },
28392889 },
28402890 .cttz = .{
2891 .ret_len = 1,
28412892 .params = &.{
28422893 .{ .kind = .overloaded },
28432894 .{ .kind = .{ .matches = 0 } },
......@@ -2846,6 +2897,7 @@ pub const Intrinsic = enum {
28462897 .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = Attribute.Memory.all(.none) } },
28472898 },
28482899 .fshl = .{
2900 .ret_len = 1,
28492901 .params = &.{
28502902 .{ .kind = .overloaded },
28512903 .{ .kind = .{ .matches = 0 } },
......@@ -2855,6 +2907,7 @@ pub const Intrinsic = enum {
28552907 .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = Attribute.Memory.all(.none) } },
28562908 },
28572909 .fshr = .{
2910 .ret_len = 1,
28582911 .params = &.{
28592912 .{ .kind = .overloaded },
28602913 .{ .kind = .{ .matches = 0 } },
......@@ -2865,55 +2918,68 @@ pub const Intrinsic = enum {
28652918 },
28662919
28672920 .@"sadd.with.overflow" = .{
2921 .ret_len = 2,
28682922 .params = &.{
2869 .{ .kind = .{ .matches_with_overflow = 1 } },
28702923 .{ .kind = .overloaded },
2871 .{ .kind = .{ .matches = 1 } },
2924 .{ .kind = .{ .change_scalar = .{ .index = 0, .scalar = .i1 } } },
2925 .{ .kind = .{ .matches = 0 } },
2926 .{ .kind = .{ .matches = 0 } },
28722927 },
28732928 .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = Attribute.Memory.all(.none) } },
28742929 },
28752930 .@"uadd.with.overflow" = .{
2931 .ret_len = 2,
28762932 .params = &.{
2877 .{ .kind = .{ .matches_with_overflow = 1 } },
28782933 .{ .kind = .overloaded },
2879 .{ .kind = .{ .matches = 1 } },
2934 .{ .kind = .{ .change_scalar = .{ .index = 0, .scalar = .i1 } } },
2935 .{ .kind = .{ .matches = 0 } },
2936 .{ .kind = .{ .matches = 0 } },
28802937 },
28812938 .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = Attribute.Memory.all(.none) } },
28822939 },
28832940 .@"ssub.with.overflow" = .{
2941 .ret_len = 2,
28842942 .params = &.{
2885 .{ .kind = .{ .matches_with_overflow = 1 } },
28862943 .{ .kind = .overloaded },
2887 .{ .kind = .{ .matches = 1 } },
2944 .{ .kind = .{ .change_scalar = .{ .index = 0, .scalar = .i1 } } },
2945 .{ .kind = .{ .matches = 0 } },
2946 .{ .kind = .{ .matches = 0 } },
28882947 },
28892948 .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = Attribute.Memory.all(.none) } },
28902949 },
28912950 .@"usub.with.overflow" = .{
2951 .ret_len = 2,
28922952 .params = &.{
2893 .{ .kind = .{ .matches_with_overflow = 1 } },
28942953 .{ .kind = .overloaded },
2895 .{ .kind = .{ .matches = 1 } },
2954 .{ .kind = .{ .change_scalar = .{ .index = 0, .scalar = .i1 } } },
2955 .{ .kind = .{ .matches = 0 } },
2956 .{ .kind = .{ .matches = 0 } },
28962957 },
28972958 .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = Attribute.Memory.all(.none) } },
28982959 },
28992960 .@"smul.with.overflow" = .{
2961 .ret_len = 2,
29002962 .params = &.{
2901 .{ .kind = .{ .matches_with_overflow = 1 } },
29022963 .{ .kind = .overloaded },
2903 .{ .kind = .{ .matches = 1 } },
2964 .{ .kind = .{ .change_scalar = .{ .index = 0, .scalar = .i1 } } },
2965 .{ .kind = .{ .matches = 0 } },
2966 .{ .kind = .{ .matches = 0 } },
29042967 },
29052968 .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = Attribute.Memory.all(.none) } },
29062969 },
29072970 .@"umul.with.overflow" = .{
2971 .ret_len = 2,
29082972 .params = &.{
2909 .{ .kind = .{ .matches_with_overflow = 1 } },
29102973 .{ .kind = .overloaded },
2911 .{ .kind = .{ .matches = 1 } },
2974 .{ .kind = .{ .change_scalar = .{ .index = 0, .scalar = .i1 } } },
2975 .{ .kind = .{ .matches = 0 } },
2976 .{ .kind = .{ .matches = 0 } },
29122977 },
29132978 .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = Attribute.Memory.all(.none) } },
29142979 },
29152980
29162981 .@"sadd.sat" = .{
2982 .ret_len = 1,
29172983 .params = &.{
29182984 .{ .kind = .overloaded },
29192985 .{ .kind = .{ .matches = 0 } },
......@@ -2922,6 +2988,7 @@ pub const Intrinsic = enum {
29222988 .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = Attribute.Memory.all(.none) } },
29232989 },
29242990 .@"uadd.sat" = .{
2991 .ret_len = 1,
29252992 .params = &.{
29262993 .{ .kind = .overloaded },
29272994 .{ .kind = .{ .matches = 0 } },
......@@ -2930,6 +2997,7 @@ pub const Intrinsic = enum {
29302997 .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = Attribute.Memory.all(.none) } },
29312998 },
29322999 .@"ssub.sat" = .{
3000 .ret_len = 1,
29333001 .params = &.{
29343002 .{ .kind = .overloaded },
29353003 .{ .kind = .{ .matches = 0 } },
......@@ -2938,6 +3006,7 @@ pub const Intrinsic = enum {
29383006 .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = Attribute.Memory.all(.none) } },
29393007 },
29403008 .@"usub.sat" = .{
3009 .ret_len = 1,
29413010 .params = &.{
29423011 .{ .kind = .overloaded },
29433012 .{ .kind = .{ .matches = 0 } },
......@@ -2946,6 +3015,7 @@ pub const Intrinsic = enum {
29463015 .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = Attribute.Memory.all(.none) } },
29473016 },
29483017 .@"sshl.sat" = .{
3018 .ret_len = 1,
29493019 .params = &.{
29503020 .{ .kind = .overloaded },
29513021 .{ .kind = .{ .matches = 0 } },
......@@ -2954,6 +3024,7 @@ pub const Intrinsic = enum {
29543024 .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = Attribute.Memory.all(.none) } },
29553025 },
29563026 .@"ushl.sat" = .{
3027 .ret_len = 1,
29573028 .params = &.{
29583029 .{ .kind = .overloaded },
29593030 .{ .kind = .{ .matches = 0 } },
......@@ -2963,6 +3034,7 @@ pub const Intrinsic = enum {
29633034 },
29643035
29653036 .@"smul.fix" = .{
3037 .ret_len = 1,
29663038 .params = &.{
29673039 .{ .kind = .overloaded },
29683040 .{ .kind = .{ .matches = 0 } },
......@@ -2972,6 +3044,7 @@ pub const Intrinsic = enum {
29723044 .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = Attribute.Memory.all(.none) } },
29733045 },
29743046 .@"umul.fix" = .{
3047 .ret_len = 1,
29753048 .params = &.{
29763049 .{ .kind = .overloaded },
29773050 .{ .kind = .{ .matches = 0 } },
......@@ -2981,6 +3054,7 @@ pub const Intrinsic = enum {
29813054 .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = Attribute.Memory.all(.none) } },
29823055 },
29833056 .@"smul.fix.sat" = .{
3057 .ret_len = 1,
29843058 .params = &.{
29853059 .{ .kind = .overloaded },
29863060 .{ .kind = .{ .matches = 0 } },
......@@ -2990,6 +3064,7 @@ pub const Intrinsic = enum {
29903064 .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = Attribute.Memory.all(.none) } },
29913065 },
29923066 .@"umul.fix.sat" = .{
3067 .ret_len = 1,
29933068 .params = &.{
29943069 .{ .kind = .overloaded },
29953070 .{ .kind = .{ .matches = 0 } },
......@@ -2999,6 +3074,7 @@ pub const Intrinsic = enum {
29993074 .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = Attribute.Memory.all(.none) } },
30003075 },
30013076 .@"sdiv.fix" = .{
3077 .ret_len = 1,
30023078 .params = &.{
30033079 .{ .kind = .overloaded },
30043080 .{ .kind = .{ .matches = 0 } },
......@@ -3008,6 +3084,7 @@ pub const Intrinsic = enum {
30083084 .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .willreturn, .{ .memory = Attribute.Memory.all(.none) } },
30093085 },
30103086 .@"udiv.fix" = .{
3087 .ret_len = 1,
30113088 .params = &.{
30123089 .{ .kind = .overloaded },
30133090 .{ .kind = .{ .matches = 0 } },
......@@ -3017,6 +3094,7 @@ pub const Intrinsic = enum {
30173094 .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .willreturn, .{ .memory = Attribute.Memory.all(.none) } },
30183095 },
30193096 .@"sdiv.fix.sat" = .{
3097 .ret_len = 1,
30203098 .params = &.{
30213099 .{ .kind = .overloaded },
30223100 .{ .kind = .{ .matches = 0 } },
......@@ -3026,6 +3104,7 @@ pub const Intrinsic = enum {
30263104 .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .willreturn, .{ .memory = Attribute.Memory.all(.none) } },
30273105 },
30283106 .@"udiv.fix.sat" = .{
3107 .ret_len = 1,
30293108 .params = &.{
30303109 .{ .kind = .overloaded },
30313110 .{ .kind = .{ .matches = 0 } },
......@@ -3036,62 +3115,67 @@ pub const Intrinsic = enum {
30363115 },
30373116
30383117 .trap = .{
3039 .params = &.{
3040 .{ .kind = .{ .type = .void } },
3041 },
3118 .ret_len = 0,
3119 .params = &.{},
30423120 .attrs = &.{ .cold, .noreturn, .nounwind, .{ .memory = .{ .inaccessiblemem = .write } } },
30433121 },
30443122 .debugtrap = .{
3045 .params = &.{
3046 .{ .kind = .{ .type = .void } },
3047 },
3123 .ret_len = 0,
3124 .params = &.{},
30483125 .attrs = &.{.nounwind},
30493126 },
30503127 .ubsantrap = .{
3128 .ret_len = 0,
30513129 .params = &.{
3052 .{ .kind = .{ .type = .void } },
30533130 .{ .kind = .{ .type = .i8 }, .attrs = &.{.immarg} },
30543131 },
30553132 .attrs = &.{ .cold, .noreturn, .nounwind },
30563133 },
30573134
30583135 .@"amdgcn.workitem.id.x" = .{
3136 .ret_len = 1,
30593137 .params = &.{
30603138 .{ .kind = .{ .type = .i32 } },
30613139 },
30623140 .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = Attribute.Memory.all(.none) } },
30633141 },
30643142 .@"amdgcn.workitem.id.y" = .{
3143 .ret_len = 1,
30653144 .params = &.{
30663145 .{ .kind = .{ .type = .i32 } },
30673146 },
30683147 .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = Attribute.Memory.all(.none) } },
30693148 },
30703149 .@"amdgcn.workitem.id.z" = .{
3150 .ret_len = 1,
30713151 .params = &.{
30723152 .{ .kind = .{ .type = .i32 } },
30733153 },
30743154 .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = Attribute.Memory.all(.none) } },
30753155 },
30763156 .@"amdgcn.workgroup.id.x" = .{
3157 .ret_len = 1,
30773158 .params = &.{
30783159 .{ .kind = .{ .type = .i32 } },
30793160 },
30803161 .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = Attribute.Memory.all(.none) } },
30813162 },
30823163 .@"amdgcn.workgroup.id.y" = .{
3164 .ret_len = 1,
30833165 .params = &.{
30843166 .{ .kind = .{ .type = .i32 } },
30853167 },
30863168 .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = Attribute.Memory.all(.none) } },
30873169 },
30883170 .@"amdgcn.workgroup.id.z" = .{
3171 .ret_len = 1,
30893172 .params = &.{
30903173 .{ .kind = .{ .type = .i32 } },
30913174 },
30923175 .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = Attribute.Memory.all(.none) } },
30933176 },
30943177 .@"amdgcn.dispatch.ptr" = .{
3178 .ret_len = 1,
30953179 .params = &.{
30963180 .{
30973181 .kind = .{ .type = Type.ptr_amdgpu_constant },
......@@ -3102,6 +3186,7 @@ pub const Intrinsic = enum {
31023186 },
31033187
31043188 .@"wasm.memory.size" = .{
3189 .ret_len = 1,
31053190 .params = &.{
31063191 .{ .kind = .overloaded },
31073192 .{ .kind = .{ .type = .i32 } },
......@@ -3109,6 +3194,7 @@ pub const Intrinsic = enum {
31093194 .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .willreturn, .{ .memory = Attribute.Memory.all(.none) } },
31103195 },
31113196 .@"wasm.memory.grow" = .{
3197 .ret_len = 1,
31123198 .params = &.{
31133199 .{ .kind = .overloaded },
31143200 .{ .kind = .{ .type = .i32 } },
......@@ -7627,8 +7713,10 @@ pub fn getIntrinsic(
76277713 const signature = Intrinsic.signatures.get(id);
76287714 const param_types = try allocator.alloc(Type, signature.params.len);
76297715 defer allocator.free(param_types);
7630 const function_attributes =
7631 try allocator.alloc(Attributes, FunctionAttributes.return_index + signature.params.len);
7716 const function_attributes = try allocator.alloc(
7717 Attributes,
7718 FunctionAttributes.params_index + (signature.params.len - signature.ret_len),
7719 );
76327720 defer allocator.free(function_attributes);
76337721
76347722 var attributes: struct {
......@@ -7651,42 +7739,37 @@ pub fn getIntrinsic(
76517739
76527740 var overload_index: usize = 0;
76537741 function_attributes[FunctionAttributes.function_index] = try attributes.get(signature.attrs);
7654 for (
7655 param_types,
7656 function_attributes[FunctionAttributes.return_index..],
7657 signature.params,
7658 ) |*param_type, *param_attributes, signature_param| {
7742 for (0.., param_types, signature.params) |param_index, *param_type, signature_param| {
76597743 switch (signature_param.kind) {
76607744 .type => |ty| param_type.* = ty,
7745 .change_scalar => |info| {
7746 assert(info.index < param_index);
7747 param_type.* = try param_types[info.index].changeScalar(info.scalar, self);
7748 },
76617749 .overloaded => {
76627750 param_type.* = overload[overload_index];
76637751 overload_index += 1;
76647752 },
7665 .overloaded_tuple => |len| {
7666 const fields = try allocator.alloc(Type, len);
7667 defer allocator.free(fields);
7668 for (fields, overload[overload_index..][0..len]) |*field, ty| field.* = ty;
7669 param_type.* = try self.structType(.normal, fields);
7670 overload_index += len;
7753 .matches => |index| {
7754 assert(index < param_index);
7755 param_type.* = param_types[index];
76717756 },
7672 .matches, .matches_tuple, .matches_with_overflow => {},
76737757 }
7674 param_attributes.* = try attributes.get(signature_param.attrs);
7758 function_attributes[
7759 if (param_index < signature.ret_len)
7760 FunctionAttributes.return_index
7761 else
7762 FunctionAttributes.params_index + (param_index - signature.ret_len)
7763 ] = try attributes.get(signature_param.attrs);
76757764 }
76767765 assert(overload_index == overload.len);
7677 for (param_types, signature.params) |*param_type, signature_param| switch (signature_param.kind) {
7678 .type, .overloaded, .overloaded_tuple => {},
7679 .matches => |param_index| param_type.* = param_types[param_index],
7680 .matches_tuple => |tuple| param_type.* =
7681 param_types[tuple.param].structFields(self)[tuple.field],
7682 .matches_with_overflow => |param_index| {
7683 const ty = param_types[param_index];
7684 param_type.* = try self.structType(.normal, &.{ ty, try ty.changeScalar(.i1, self) });
7685 },
7686 };
76877766
76887767 const function_index =
7689 try self.addFunction(try self.fnType(param_types[0], param_types[1..], .normal), name);
7768 try self.addFunction(try self.fnType(switch (signature.ret_len) {
7769 0 => .void,
7770 1 => param_types[0],
7771 else => try self.structType(.normal, param_types[0..signature.ret_len]),
7772 }, param_types[signature.ret_len..], .normal), name);
76907773 function_index.ptr(self).attributes = try self.fnAttrs(function_attributes);
76917774 return function_index;
76927775}