| ... | ... | @@ -98,6 +98,10 @@ static bool instr_is_comptime(IrInstruction *instruction) { |
| 98 | 98 | return instruction->value.special != ConstValSpecialRuntime; |
| 99 | 99 | } |
| 100 | 100 | |
| 101 | static bool instr_is_unreachable(IrInstruction *instruction) { |
| 102 | return instruction->value.type && instruction->value.type->id == TypeTableEntryIdUnreachable; |
| 103 | } |
| 104 | |
| 101 | 105 | static void ir_link_new_instruction(IrInstruction *new_instruction, IrInstruction *old_instruction) { |
| 102 | 106 | new_instruction->other = old_instruction; |
| 103 | 107 | old_instruction->other = new_instruction; |
| ... | ... | @@ -112,8 +116,10 @@ static void ir_ref_bb(IrBasicBlock *bb) { |
| 112 | 116 | bb->ref_count += 1; |
| 113 | 117 | } |
| 114 | 118 | |
| 115 | | static void ir_ref_instruction(IrInstruction *instruction) { |
| 119 | static void ir_ref_instruction(IrInstruction *instruction, IrBasicBlock *cur_bb) { |
| 116 | 120 | instruction->ref_count += 1; |
| 121 | if (instruction->owner_bb != cur_bb) |
| 122 | ir_ref_bb(instruction->owner_bb); |
| 117 | 123 | } |
| 118 | 124 | |
| 119 | 125 | static void ir_ref_var(VariableTableEntry *var) { |
| ... | ... | @@ -499,7 +505,7 @@ static IrInstruction *ir_build_cast(IrBuilder *irb, Scope *scope, AstNode *sourc |
| 499 | 505 | cast_instruction->value = value; |
| 500 | 506 | cast_instruction->cast_op = cast_op; |
| 501 | 507 | |
| 502 | | ir_ref_instruction(value); |
| 508 | ir_ref_instruction(value, irb->current_basic_block); |
| 503 | 509 | |
| 504 | 510 | return &cast_instruction->base; |
| 505 | 511 | } |
| ... | ... | @@ -515,10 +521,10 @@ static IrInstruction *ir_build_cond_br(IrBuilder *irb, Scope *scope, AstNode *so |
| 515 | 521 | cond_br_instruction->else_block = else_block; |
| 516 | 522 | cond_br_instruction->is_comptime = is_comptime; |
| 517 | 523 | |
| 518 | | ir_ref_instruction(condition); |
| 524 | ir_ref_instruction(condition, irb->current_basic_block); |
| 519 | 525 | ir_ref_bb(then_block); |
| 520 | 526 | ir_ref_bb(else_block); |
| 521 | | if (is_comptime) ir_ref_instruction(is_comptime); |
| 527 | if (is_comptime) ir_ref_instruction(is_comptime, irb->current_basic_block); |
| 522 | 528 | |
| 523 | 529 | return &cond_br_instruction->base; |
| 524 | 530 | } |
| ... | ... | @@ -538,7 +544,7 @@ static IrInstruction *ir_build_return(IrBuilder *irb, Scope *scope, AstNode *sou |
| 538 | 544 | return_instruction->base.value.special = ConstValSpecialStatic; |
| 539 | 545 | return_instruction->value = return_value; |
| 540 | 546 | |
| 541 | | ir_ref_instruction(return_value); |
| 547 | ir_ref_instruction(return_value, irb->current_basic_block); |
| 542 | 548 | |
| 543 | 549 | return &return_instruction->base; |
| 544 | 550 | } |
| ... | ... | @@ -699,8 +705,8 @@ static IrInstruction *ir_build_bin_op(IrBuilder *irb, Scope *scope, AstNode *sou |
| 699 | 705 | bin_op_instruction->op2 = op2; |
| 700 | 706 | bin_op_instruction->safety_check_on = safety_check_on; |
| 701 | 707 | |
| 702 | | ir_ref_instruction(op1); |
| 703 | | ir_ref_instruction(op2); |
| 708 | ir_ref_instruction(op1, irb->current_basic_block); |
| 709 | ir_ref_instruction(op2, irb->current_basic_block); |
| 704 | 710 | |
| 705 | 711 | return &bin_op_instruction->base; |
| 706 | 712 | } |
| ... | ... | @@ -738,8 +744,8 @@ static IrInstruction *ir_build_elem_ptr(IrBuilder *irb, Scope *scope, AstNode *s |
| 738 | 744 | instruction->elem_index = elem_index; |
| 739 | 745 | instruction->safety_check_on = safety_check_on; |
| 740 | 746 | |
| 741 | | ir_ref_instruction(array_ptr); |
| 742 | | ir_ref_instruction(elem_index); |
| 747 | ir_ref_instruction(array_ptr, irb->current_basic_block); |
| 748 | ir_ref_instruction(elem_index, irb->current_basic_block); |
| 743 | 749 | |
| 744 | 750 | return &instruction->base; |
| 745 | 751 | } |
| ... | ... | @@ -760,7 +766,7 @@ static IrInstruction *ir_build_field_ptr(IrBuilder *irb, Scope *scope, AstNode * |
| 760 | 766 | instruction->container_ptr = container_ptr; |
| 761 | 767 | instruction->field_name = field_name; |
| 762 | 768 | |
| 763 | | ir_ref_instruction(container_ptr); |
| 769 | ir_ref_instruction(container_ptr, irb->current_basic_block); |
| 764 | 770 | |
| 765 | 771 | return &instruction->base; |
| 766 | 772 | } |
| ... | ... | @@ -772,7 +778,7 @@ static IrInstruction *ir_build_struct_field_ptr(IrBuilder *irb, Scope *scope, As |
| 772 | 778 | instruction->struct_ptr = struct_ptr; |
| 773 | 779 | instruction->field = field; |
| 774 | 780 | |
| 775 | | ir_ref_instruction(struct_ptr); |
| 781 | ir_ref_instruction(struct_ptr, irb->current_basic_block); |
| 776 | 782 | |
| 777 | 783 | return &instruction->base; |
| 778 | 784 | } |
| ... | ... | @@ -793,7 +799,7 @@ static IrInstruction *ir_build_enum_field_ptr(IrBuilder *irb, Scope *scope, AstN |
| 793 | 799 | instruction->enum_ptr = enum_ptr; |
| 794 | 800 | instruction->field = field; |
| 795 | 801 | |
| 796 | | ir_ref_instruction(enum_ptr); |
| 802 | ir_ref_instruction(enum_ptr, irb->current_basic_block); |
| 797 | 803 | |
| 798 | 804 | return &instruction->base; |
| 799 | 805 | } |
| ... | ... | @@ -819,9 +825,9 @@ static IrInstruction *ir_build_call(IrBuilder *irb, Scope *scope, AstNode *sourc |
| 819 | 825 | call_instruction->arg_count = arg_count; |
| 820 | 826 | |
| 821 | 827 | if (fn_ref) |
| 822 | | ir_ref_instruction(fn_ref); |
| 828 | ir_ref_instruction(fn_ref, irb->current_basic_block); |
| 823 | 829 | for (size_t i = 0; i < arg_count; i += 1) |
| 824 | | ir_ref_instruction(args[i]); |
| 830 | ir_ref_instruction(args[i], irb->current_basic_block); |
| 825 | 831 | |
| 826 | 832 | return &call_instruction->base; |
| 827 | 833 | } |
| ... | ... | @@ -849,7 +855,7 @@ static IrInstruction *ir_build_phi(IrBuilder *irb, Scope *scope, AstNode *source |
| 849 | 855 | |
| 850 | 856 | for (size_t i = 0; i < incoming_count; i += 1) { |
| 851 | 857 | ir_ref_bb(incoming_blocks[i]); |
| 852 | | ir_ref_instruction(incoming_values[i]); |
| 858 | ir_ref_instruction(incoming_values[i], irb->current_basic_block); |
| 853 | 859 | } |
| 854 | 860 | |
| 855 | 861 | return &phi_instruction->base; |
| ... | ... | @@ -874,7 +880,7 @@ static IrInstruction *ir_create_br(IrBuilder *irb, Scope *scope, AstNode *source |
| 874 | 880 | br_instruction->is_comptime = is_comptime; |
| 875 | 881 | |
| 876 | 882 | ir_ref_bb(dest_block); |
| 877 | | if (is_comptime) ir_ref_instruction(is_comptime); |
| 883 | if (is_comptime) ir_ref_instruction(is_comptime, irb->current_basic_block); |
| 878 | 884 | |
| 879 | 885 | return &br_instruction->base; |
| 880 | 886 | } |
| ... | ... | @@ -898,7 +904,7 @@ static IrInstruction *ir_build_un_op(IrBuilder *irb, Scope *scope, AstNode *sour |
| 898 | 904 | br_instruction->op_id = op_id; |
| 899 | 905 | br_instruction->value = value; |
| 900 | 906 | |
| 901 | | ir_ref_instruction(value); |
| 907 | ir_ref_instruction(value, irb->current_basic_block); |
| 902 | 908 | |
| 903 | 909 | return &br_instruction->base; |
| 904 | 910 | } |
| ... | ... | @@ -921,9 +927,9 @@ static IrInstruction *ir_build_container_init_list(IrBuilder *irb, Scope *scope, |
| 921 | 927 | container_init_list_instruction->item_count = item_count; |
| 922 | 928 | container_init_list_instruction->items = items; |
| 923 | 929 | |
| 924 | | ir_ref_instruction(container_type); |
| 930 | ir_ref_instruction(container_type, irb->current_basic_block); |
| 925 | 931 | for (size_t i = 0; i < item_count; i += 1) { |
| 926 | | ir_ref_instruction(items[i]); |
| 932 | ir_ref_instruction(items[i], irb->current_basic_block); |
| 927 | 933 | } |
| 928 | 934 | |
| 929 | 935 | return &container_init_list_instruction->base; |
| ... | ... | @@ -947,9 +953,9 @@ static IrInstruction *ir_build_container_init_fields(IrBuilder *irb, Scope *scop |
| 947 | 953 | container_init_fields_instruction->field_count = field_count; |
| 948 | 954 | container_init_fields_instruction->fields = fields; |
| 949 | 955 | |
| 950 | | ir_ref_instruction(container_type); |
| 956 | ir_ref_instruction(container_type, irb->current_basic_block); |
| 951 | 957 | for (size_t i = 0; i < field_count; i += 1) { |
| 952 | | ir_ref_instruction(fields[i].value); |
| 958 | ir_ref_instruction(fields[i].value, irb->current_basic_block); |
| 953 | 959 | } |
| 954 | 960 | |
| 955 | 961 | return &container_init_fields_instruction->base; |
| ... | ... | @@ -964,7 +970,7 @@ static IrInstruction *ir_build_struct_init(IrBuilder *irb, Scope *scope, AstNode |
| 964 | 970 | struct_init_instruction->fields = fields; |
| 965 | 971 | |
| 966 | 972 | for (size_t i = 0; i < field_count; i += 1) |
| 967 | | ir_ref_instruction(fields[i].value); |
| 973 | ir_ref_instruction(fields[i].value, irb->current_basic_block); |
| 968 | 974 | |
| 969 | 975 | return &struct_init_instruction->base; |
| 970 | 976 | } |
| ... | ... | @@ -1001,8 +1007,8 @@ static IrInstruction *ir_build_store_ptr(IrBuilder *irb, Scope *scope, AstNode * |
| 1001 | 1007 | instruction->ptr = ptr; |
| 1002 | 1008 | instruction->value = value; |
| 1003 | 1009 | |
| 1004 | | ir_ref_instruction(ptr); |
| 1005 | | ir_ref_instruction(value); |
| 1010 | ir_ref_instruction(ptr, irb->current_basic_block); |
| 1011 | ir_ref_instruction(value, irb->current_basic_block); |
| 1006 | 1012 | |
| 1007 | 1013 | return &instruction->base; |
| 1008 | 1014 | } |
| ... | ... | @@ -1026,8 +1032,8 @@ static IrInstruction *ir_build_var_decl(IrBuilder *irb, Scope *scope, AstNode *s |
| 1026 | 1032 | decl_var_instruction->var_type = var_type; |
| 1027 | 1033 | decl_var_instruction->init_value = init_value; |
| 1028 | 1034 | |
| 1029 | | if (var_type) ir_ref_instruction(var_type); |
| 1030 | | ir_ref_instruction(init_value); |
| 1035 | if (var_type) ir_ref_instruction(var_type, irb->current_basic_block); |
| 1036 | ir_ref_instruction(init_value, irb->current_basic_block); |
| 1031 | 1037 | |
| 1032 | 1038 | return &decl_var_instruction->base; |
| 1033 | 1039 | } |
| ... | ... | @@ -1045,7 +1051,7 @@ static IrInstruction *ir_build_load_ptr(IrBuilder *irb, Scope *scope, AstNode *s |
| 1045 | 1051 | IrInstructionLoadPtr *instruction = ir_build_instruction<IrInstructionLoadPtr>(irb, scope, source_node); |
| 1046 | 1052 | instruction->ptr = ptr; |
| 1047 | 1053 | |
| 1048 | | ir_ref_instruction(ptr); |
| 1054 | ir_ref_instruction(ptr, irb->current_basic_block); |
| 1049 | 1055 | |
| 1050 | 1056 | return &instruction->base; |
| 1051 | 1057 | } |
| ... | ... | @@ -1061,7 +1067,7 @@ static IrInstruction *ir_build_typeof(IrBuilder *irb, Scope *scope, AstNode *sou |
| 1061 | 1067 | IrInstructionTypeOf *instruction = ir_build_instruction<IrInstructionTypeOf>(irb, scope, source_node); |
| 1062 | 1068 | instruction->value = value; |
| 1063 | 1069 | |
| 1064 | | ir_ref_instruction(value); |
| 1070 | ir_ref_instruction(value, irb->current_basic_block); |
| 1065 | 1071 | |
| 1066 | 1072 | return &instruction->base; |
| 1067 | 1073 | } |
| ... | ... | @@ -1070,7 +1076,7 @@ static IrInstruction *ir_build_to_ptr_type(IrBuilder *irb, Scope *scope, AstNode |
| 1070 | 1076 | IrInstructionToPtrType *instruction = ir_build_instruction<IrInstructionToPtrType>(irb, scope, source_node); |
| 1071 | 1077 | instruction->value = value; |
| 1072 | 1078 | |
| 1073 | | ir_ref_instruction(value); |
| 1079 | ir_ref_instruction(value, irb->current_basic_block); |
| 1074 | 1080 | |
| 1075 | 1081 | return &instruction->base; |
| 1076 | 1082 | } |
| ... | ... | @@ -1082,7 +1088,7 @@ static IrInstruction *ir_build_ptr_type_child(IrBuilder *irb, Scope *scope, AstN |
| 1082 | 1088 | irb, scope, source_node); |
| 1083 | 1089 | instruction->value = value; |
| 1084 | 1090 | |
| 1085 | | ir_ref_instruction(value); |
| 1091 | ir_ref_instruction(value, irb->current_basic_block); |
| 1086 | 1092 | |
| 1087 | 1093 | return &instruction->base; |
| 1088 | 1094 | } |
| ... | ... | @@ -1093,7 +1099,7 @@ static IrInstruction *ir_build_set_fn_test(IrBuilder *irb, Scope *scope, AstNode |
| 1093 | 1099 | IrInstructionSetFnTest *instruction = ir_build_instruction<IrInstructionSetFnTest>(irb, scope, source_node); |
| 1094 | 1100 | instruction->fn_value = fn_value; |
| 1095 | 1101 | |
| 1096 | | ir_ref_instruction(fn_value); |
| 1102 | ir_ref_instruction(fn_value, irb->current_basic_block); |
| 1097 | 1103 | |
| 1098 | 1104 | return &instruction->base; |
| 1099 | 1105 | } |
| ... | ... | @@ -1105,8 +1111,8 @@ static IrInstruction *ir_build_set_fn_visible(IrBuilder *irb, Scope *scope, AstN |
| 1105 | 1111 | instruction->fn_value = fn_value; |
| 1106 | 1112 | instruction->is_visible = is_visible; |
| 1107 | 1113 | |
| 1108 | | ir_ref_instruction(fn_value); |
| 1109 | | ir_ref_instruction(is_visible); |
| 1114 | ir_ref_instruction(fn_value, irb->current_basic_block); |
| 1115 | ir_ref_instruction(is_visible, irb->current_basic_block); |
| 1110 | 1116 | |
| 1111 | 1117 | return &instruction->base; |
| 1112 | 1118 | } |
| ... | ... | @@ -1118,8 +1124,8 @@ static IrInstruction *ir_build_set_debug_safety(IrBuilder *irb, Scope *scope, As |
| 1118 | 1124 | instruction->scope_value = scope_value; |
| 1119 | 1125 | instruction->debug_safety_on = debug_safety_on; |
| 1120 | 1126 | |
| 1121 | | ir_ref_instruction(scope_value); |
| 1122 | | ir_ref_instruction(debug_safety_on); |
| 1127 | ir_ref_instruction(scope_value, irb->current_basic_block); |
| 1128 | ir_ref_instruction(debug_safety_on, irb->current_basic_block); |
| 1123 | 1129 | |
| 1124 | 1130 | return &instruction->base; |
| 1125 | 1131 | } |
| ... | ... | @@ -1131,8 +1137,8 @@ static IrInstruction *ir_build_array_type(IrBuilder *irb, Scope *scope, AstNode |
| 1131 | 1137 | instruction->size = size; |
| 1132 | 1138 | instruction->child_type = child_type; |
| 1133 | 1139 | |
| 1134 | | ir_ref_instruction(size); |
| 1135 | | ir_ref_instruction(child_type); |
| 1140 | ir_ref_instruction(size, irb->current_basic_block); |
| 1141 | ir_ref_instruction(child_type, irb->current_basic_block); |
| 1136 | 1142 | |
| 1137 | 1143 | return &instruction->base; |
| 1138 | 1144 | } |
| ... | ... | @@ -1144,7 +1150,7 @@ static IrInstruction *ir_build_slice_type(IrBuilder *irb, Scope *scope, AstNode |
| 1144 | 1150 | instruction->is_const = is_const; |
| 1145 | 1151 | instruction->child_type = child_type; |
| 1146 | 1152 | |
| 1147 | | ir_ref_instruction(child_type); |
| 1153 | ir_ref_instruction(child_type, irb->current_basic_block); |
| 1148 | 1154 | |
| 1149 | 1155 | return &instruction->base; |
| 1150 | 1156 | } |
| ... | ... | @@ -1162,12 +1168,12 @@ static IrInstruction *ir_build_asm(IrBuilder *irb, Scope *scope, AstNode *source |
| 1162 | 1168 | assert(source_node->type == NodeTypeAsmExpr); |
| 1163 | 1169 | for (size_t i = 0; i < source_node->data.asm_expr.output_list.length; i += 1) { |
| 1164 | 1170 | IrInstruction *output_type = output_types[i]; |
| 1165 | | if (output_type) ir_ref_instruction(output_type); |
| 1171 | if (output_type) ir_ref_instruction(output_type, irb->current_basic_block); |
| 1166 | 1172 | } |
| 1167 | 1173 | |
| 1168 | 1174 | for (size_t i = 0; i < source_node->data.asm_expr.input_list.length; i += 1) { |
| 1169 | 1175 | IrInstruction *input_value = input_list[i]; |
| 1170 | | ir_ref_instruction(input_value); |
| 1176 | ir_ref_instruction(input_value, irb->current_basic_block); |
| 1171 | 1177 | } |
| 1172 | 1178 | |
| 1173 | 1179 | return &instruction->base; |
| ... | ... | @@ -1186,7 +1192,7 @@ static IrInstruction *ir_build_compile_var(IrBuilder *irb, Scope *scope, AstNode |
| 1186 | 1192 | IrInstructionCompileVar *instruction = ir_build_instruction<IrInstructionCompileVar>(irb, scope, source_node); |
| 1187 | 1193 | instruction->name = name; |
| 1188 | 1194 | |
| 1189 | | ir_ref_instruction(name); |
| 1195 | ir_ref_instruction(name, irb->current_basic_block); |
| 1190 | 1196 | |
| 1191 | 1197 | return &instruction->base; |
| 1192 | 1198 | } |
| ... | ... | @@ -1195,7 +1201,7 @@ static IrInstruction *ir_build_size_of(IrBuilder *irb, Scope *scope, AstNode *so |
| 1195 | 1201 | IrInstructionSizeOf *instruction = ir_build_instruction<IrInstructionSizeOf>(irb, scope, source_node); |
| 1196 | 1202 | instruction->type_value = type_value; |
| 1197 | 1203 | |
| 1198 | | ir_ref_instruction(type_value); |
| 1204 | ir_ref_instruction(type_value, irb->current_basic_block); |
| 1199 | 1205 | |
| 1200 | 1206 | return &instruction->base; |
| 1201 | 1207 | } |
| ... | ... | @@ -1204,7 +1210,7 @@ static IrInstruction *ir_build_test_null(IrBuilder *irb, Scope *scope, AstNode * |
| 1204 | 1210 | IrInstructionTestNonNull *instruction = ir_build_instruction<IrInstructionTestNonNull>(irb, scope, source_node); |
| 1205 | 1211 | instruction->value = value; |
| 1206 | 1212 | |
| 1207 | | ir_ref_instruction(value); |
| 1213 | ir_ref_instruction(value, irb->current_basic_block); |
| 1208 | 1214 | |
| 1209 | 1215 | return &instruction->base; |
| 1210 | 1216 | } |
| ... | ... | @@ -1225,7 +1231,7 @@ static IrInstruction *ir_build_unwrap_maybe(IrBuilder *irb, Scope *scope, AstNod |
| 1225 | 1231 | instruction->value = value; |
| 1226 | 1232 | instruction->safety_check_on = safety_check_on; |
| 1227 | 1233 | |
| 1228 | | ir_ref_instruction(value); |
| 1234 | ir_ref_instruction(value, irb->current_basic_block); |
| 1229 | 1235 | |
| 1230 | 1236 | return &instruction->base; |
| 1231 | 1237 | } |
| ... | ... | @@ -1243,7 +1249,7 @@ static IrInstruction *ir_build_maybe_wrap(IrBuilder *irb, Scope *scope, AstNode |
| 1243 | 1249 | IrInstructionMaybeWrap *instruction = ir_build_instruction<IrInstructionMaybeWrap>(irb, scope, source_node); |
| 1244 | 1250 | instruction->value = value; |
| 1245 | 1251 | |
| 1246 | | ir_ref_instruction(value); |
| 1252 | ir_ref_instruction(value, irb->current_basic_block); |
| 1247 | 1253 | |
| 1248 | 1254 | return &instruction->base; |
| 1249 | 1255 | } |
| ... | ... | @@ -1252,7 +1258,7 @@ static IrInstruction *ir_build_err_wrap_payload(IrBuilder *irb, Scope *scope, As |
| 1252 | 1258 | IrInstructionErrWrapPayload *instruction = ir_build_instruction<IrInstructionErrWrapPayload>(irb, scope, source_node); |
| 1253 | 1259 | instruction->value = value; |
| 1254 | 1260 | |
| 1255 | | ir_ref_instruction(value); |
| 1261 | ir_ref_instruction(value, irb->current_basic_block); |
| 1256 | 1262 | |
| 1257 | 1263 | return &instruction->base; |
| 1258 | 1264 | } |
| ... | ... | @@ -1261,7 +1267,7 @@ static IrInstruction *ir_build_err_wrap_code(IrBuilder *irb, Scope *scope, AstNo |
| 1261 | 1267 | IrInstructionErrWrapCode *instruction = ir_build_instruction<IrInstructionErrWrapCode>(irb, scope, source_node); |
| 1262 | 1268 | instruction->value = value; |
| 1263 | 1269 | |
| 1264 | | ir_ref_instruction(value); |
| 1270 | ir_ref_instruction(value, irb->current_basic_block); |
| 1265 | 1271 | |
| 1266 | 1272 | return &instruction->base; |
| 1267 | 1273 | } |
| ... | ... | @@ -1270,7 +1276,7 @@ static IrInstruction *ir_build_clz(IrBuilder *irb, Scope *scope, AstNode *source |
| 1270 | 1276 | IrInstructionClz *instruction = ir_build_instruction<IrInstructionClz>(irb, scope, source_node); |
| 1271 | 1277 | instruction->value = value; |
| 1272 | 1278 | |
| 1273 | | ir_ref_instruction(value); |
| 1279 | ir_ref_instruction(value, irb->current_basic_block); |
| 1274 | 1280 | |
| 1275 | 1281 | return &instruction->base; |
| 1276 | 1282 | } |
| ... | ... | @@ -1285,7 +1291,7 @@ static IrInstruction *ir_build_ctz(IrBuilder *irb, Scope *scope, AstNode *source |
| 1285 | 1291 | IrInstructionCtz *instruction = ir_build_instruction<IrInstructionCtz>(irb, scope, source_node); |
| 1286 | 1292 | instruction->value = value; |
| 1287 | 1293 | |
| 1288 | | ir_ref_instruction(value); |
| 1294 | ir_ref_instruction(value, irb->current_basic_block); |
| 1289 | 1295 | |
| 1290 | 1296 | return &instruction->base; |
| 1291 | 1297 | } |
| ... | ... | @@ -1308,12 +1314,12 @@ static IrInstruction *ir_build_switch_br(IrBuilder *irb, Scope *scope, AstNode * |
| 1308 | 1314 | instruction->cases = cases; |
| 1309 | 1315 | instruction->is_comptime = is_comptime; |
| 1310 | 1316 | |
| 1311 | | ir_ref_instruction(target_value); |
| 1312 | | if (is_comptime) ir_ref_instruction(is_comptime); |
| 1317 | ir_ref_instruction(target_value, irb->current_basic_block); |
| 1318 | if (is_comptime) ir_ref_instruction(is_comptime, irb->current_basic_block); |
| 1313 | 1319 | ir_ref_bb(else_block); |
| 1314 | 1320 | |
| 1315 | 1321 | for (size_t i = 0; i < case_count; i += 1) { |
| 1316 | | ir_ref_instruction(cases[i].value); |
| 1322 | ir_ref_instruction(cases[i].value, irb->current_basic_block); |
| 1317 | 1323 | ir_ref_bb(cases[i].block); |
| 1318 | 1324 | } |
| 1319 | 1325 | |
| ... | ... | @@ -1336,7 +1342,7 @@ static IrInstruction *ir_build_switch_target(IrBuilder *irb, Scope *scope, AstNo |
| 1336 | 1342 | IrInstructionSwitchTarget *instruction = ir_build_instruction<IrInstructionSwitchTarget>(irb, scope, source_node); |
| 1337 | 1343 | instruction->target_value_ptr = target_value_ptr; |
| 1338 | 1344 | |
| 1339 | | ir_ref_instruction(target_value_ptr); |
| 1345 | ir_ref_instruction(target_value_ptr, irb->current_basic_block); |
| 1340 | 1346 | |
| 1341 | 1347 | return &instruction->base; |
| 1342 | 1348 | } |
| ... | ... | @@ -1348,8 +1354,8 @@ static IrInstruction *ir_build_switch_var(IrBuilder *irb, Scope *scope, AstNode |
| 1348 | 1354 | instruction->target_value_ptr = target_value_ptr; |
| 1349 | 1355 | instruction->prong_value = prong_value; |
| 1350 | 1356 | |
| 1351 | | ir_ref_instruction(target_value_ptr); |
| 1352 | | ir_ref_instruction(prong_value); |
| 1357 | ir_ref_instruction(target_value_ptr, irb->current_basic_block); |
| 1358 | ir_ref_instruction(prong_value, irb->current_basic_block); |
| 1353 | 1359 | |
| 1354 | 1360 | return &instruction->base; |
| 1355 | 1361 | } |
| ... | ... | @@ -1358,7 +1364,7 @@ static IrInstruction *ir_build_enum_tag(IrBuilder *irb, Scope *scope, AstNode *s |
| 1358 | 1364 | IrInstructionEnumTag *instruction = ir_build_instruction<IrInstructionEnumTag>(irb, scope, source_node); |
| 1359 | 1365 | instruction->value = value; |
| 1360 | 1366 | |
| 1361 | | ir_ref_instruction(value); |
| 1367 | ir_ref_instruction(value, irb->current_basic_block); |
| 1362 | 1368 | |
| 1363 | 1369 | return &instruction->base; |
| 1364 | 1370 | } |
| ... | ... | @@ -1374,7 +1380,7 @@ static IrInstruction *ir_build_static_eval(IrBuilder *irb, Scope *scope, AstNode |
| 1374 | 1380 | IrInstructionStaticEval *instruction = ir_build_instruction<IrInstructionStaticEval>(irb, scope, source_node); |
| 1375 | 1381 | instruction->value = value; |
| 1376 | 1382 | |
| 1377 | | ir_ref_instruction(value); |
| 1383 | ir_ref_instruction(value, irb->current_basic_block); |
| 1378 | 1384 | |
| 1379 | 1385 | return &instruction->base; |
| 1380 | 1386 | } |
| ... | ... | @@ -1383,7 +1389,7 @@ static IrInstruction *ir_build_import(IrBuilder *irb, Scope *scope, AstNode *sou |
| 1383 | 1389 | IrInstructionImport *instruction = ir_build_instruction<IrInstructionImport>(irb, scope, source_node); |
| 1384 | 1390 | instruction->name = name; |
| 1385 | 1391 | |
| 1386 | | ir_ref_instruction(name); |
| 1392 | ir_ref_instruction(name, irb->current_basic_block); |
| 1387 | 1393 | |
| 1388 | 1394 | return &instruction->base; |
| 1389 | 1395 | } |
| ... | ... | @@ -1392,7 +1398,7 @@ static IrInstruction *ir_build_array_len(IrBuilder *irb, Scope *scope, AstNode * |
| 1392 | 1398 | IrInstructionArrayLen *instruction = ir_build_instruction<IrInstructionArrayLen>(irb, scope, source_node); |
| 1393 | 1399 | instruction->array_value = array_value; |
| 1394 | 1400 | |
| 1395 | | ir_ref_instruction(array_value); |
| 1401 | ir_ref_instruction(array_value, irb->current_basic_block); |
| 1396 | 1402 | |
| 1397 | 1403 | return &instruction->base; |
| 1398 | 1404 | } |
| ... | ... | @@ -1404,7 +1410,7 @@ static IrInstruction *ir_build_ref(IrBuilder *irb, Scope *scope, AstNode *source |
| 1404 | 1410 | instruction->value = value; |
| 1405 | 1411 | instruction->is_const = is_const; |
| 1406 | 1412 | |
| 1407 | | ir_ref_instruction(value); |
| 1413 | ir_ref_instruction(value, irb->current_basic_block); |
| 1408 | 1414 | |
| 1409 | 1415 | return &instruction->base; |
| 1410 | 1416 | } |
| ... | ... | @@ -1422,7 +1428,7 @@ static IrInstruction *ir_build_min_value(IrBuilder *irb, Scope *scope, AstNode * |
| 1422 | 1428 | IrInstructionMinValue *instruction = ir_build_instruction<IrInstructionMinValue>(irb, scope, source_node); |
| 1423 | 1429 | instruction->value = value; |
| 1424 | 1430 | |
| 1425 | | ir_ref_instruction(value); |
| 1431 | ir_ref_instruction(value, irb->current_basic_block); |
| 1426 | 1432 | |
| 1427 | 1433 | return &instruction->base; |
| 1428 | 1434 | } |
| ... | ... | @@ -1431,7 +1437,7 @@ static IrInstruction *ir_build_max_value(IrBuilder *irb, Scope *scope, AstNode * |
| 1431 | 1437 | IrInstructionMaxValue *instruction = ir_build_instruction<IrInstructionMaxValue>(irb, scope, source_node); |
| 1432 | 1438 | instruction->value = value; |
| 1433 | 1439 | |
| 1434 | | ir_ref_instruction(value); |
| 1440 | ir_ref_instruction(value, irb->current_basic_block); |
| 1435 | 1441 | |
| 1436 | 1442 | return &instruction->base; |
| 1437 | 1443 | } |
| ... | ... | @@ -1440,7 +1446,7 @@ static IrInstruction *ir_build_compile_err(IrBuilder *irb, Scope *scope, AstNode |
| 1440 | 1446 | IrInstructionCompileErr *instruction = ir_build_instruction<IrInstructionCompileErr>(irb, scope, source_node); |
| 1441 | 1447 | instruction->msg = msg; |
| 1442 | 1448 | |
| 1443 | | ir_ref_instruction(msg); |
| 1449 | ir_ref_instruction(msg, irb->current_basic_block); |
| 1444 | 1450 | |
| 1445 | 1451 | return &instruction->base; |
| 1446 | 1452 | } |
| ... | ... | @@ -1449,7 +1455,7 @@ static IrInstruction *ir_build_err_name(IrBuilder *irb, Scope *scope, AstNode *s |
| 1449 | 1455 | IrInstructionErrName *instruction = ir_build_instruction<IrInstructionErrName>(irb, scope, source_node); |
| 1450 | 1456 | instruction->value = value; |
| 1451 | 1457 | |
| 1452 | | ir_ref_instruction(value); |
| 1458 | ir_ref_instruction(value, irb->current_basic_block); |
| 1453 | 1459 | |
| 1454 | 1460 | return &instruction->base; |
| 1455 | 1461 | } |
| ... | ... | @@ -1470,7 +1476,7 @@ static IrInstruction *ir_build_c_include(IrBuilder *irb, Scope *scope, AstNode * |
| 1470 | 1476 | IrInstructionCInclude *instruction = ir_build_instruction<IrInstructionCInclude>(irb, scope, source_node); |
| 1471 | 1477 | instruction->name = name; |
| 1472 | 1478 | |
| 1473 | | ir_ref_instruction(name); |
| 1479 | ir_ref_instruction(name, irb->current_basic_block); |
| 1474 | 1480 | |
| 1475 | 1481 | return &instruction->base; |
| 1476 | 1482 | } |
| ... | ... | @@ -1480,8 +1486,8 @@ static IrInstruction *ir_build_c_define(IrBuilder *irb, Scope *scope, AstNode *s |
| 1480 | 1486 | instruction->name = name; |
| 1481 | 1487 | instruction->value = value; |
| 1482 | 1488 | |
| 1483 | | ir_ref_instruction(name); |
| 1484 | | ir_ref_instruction(value); |
| 1489 | ir_ref_instruction(name, irb->current_basic_block); |
| 1490 | ir_ref_instruction(value, irb->current_basic_block); |
| 1485 | 1491 | |
| 1486 | 1492 | return &instruction->base; |
| 1487 | 1493 | } |
| ... | ... | @@ -1490,7 +1496,7 @@ static IrInstruction *ir_build_c_undef(IrBuilder *irb, Scope *scope, AstNode *so |
| 1490 | 1496 | IrInstructionCUndef *instruction = ir_build_instruction<IrInstructionCUndef>(irb, scope, source_node); |
| 1491 | 1497 | instruction->name = name; |
| 1492 | 1498 | |
| 1493 | | ir_ref_instruction(name); |
| 1499 | ir_ref_instruction(name, irb->current_basic_block); |
| 1494 | 1500 | |
| 1495 | 1501 | return &instruction->base; |
| 1496 | 1502 | } |
| ... | ... | @@ -1499,7 +1505,7 @@ static IrInstruction *ir_build_embed_file(IrBuilder *irb, Scope *scope, AstNode |
| 1499 | 1505 | IrInstructionEmbedFile *instruction = ir_build_instruction<IrInstructionEmbedFile>(irb, scope, source_node); |
| 1500 | 1506 | instruction->name = name; |
| 1501 | 1507 | |
| 1502 | | ir_ref_instruction(name); |
| 1508 | ir_ref_instruction(name, irb->current_basic_block); |
| 1503 | 1509 | |
| 1504 | 1510 | return &instruction->base; |
| 1505 | 1511 | } |
| ... | ... | @@ -1517,11 +1523,11 @@ static IrInstruction *ir_build_cmpxchg(IrBuilder *irb, Scope *scope, AstNode *so |
| 1517 | 1523 | instruction->success_order = success_order; |
| 1518 | 1524 | instruction->failure_order = failure_order; |
| 1519 | 1525 | |
| 1520 | | ir_ref_instruction(ptr); |
| 1521 | | ir_ref_instruction(cmp_value); |
| 1522 | | ir_ref_instruction(new_value); |
| 1523 | | ir_ref_instruction(success_order_value); |
| 1524 | | ir_ref_instruction(failure_order_value); |
| 1526 | ir_ref_instruction(ptr, irb->current_basic_block); |
| 1527 | ir_ref_instruction(cmp_value, irb->current_basic_block); |
| 1528 | ir_ref_instruction(new_value, irb->current_basic_block); |
| 1529 | ir_ref_instruction(success_order_value, irb->current_basic_block); |
| 1530 | ir_ref_instruction(failure_order_value, irb->current_basic_block); |
| 1525 | 1531 | |
| 1526 | 1532 | return &instruction->base; |
| 1527 | 1533 | } |
| ... | ... | @@ -1541,7 +1547,7 @@ static IrInstruction *ir_build_fence(IrBuilder *irb, Scope *scope, AstNode *sour |
| 1541 | 1547 | instruction->order_value = order_value; |
| 1542 | 1548 | instruction->order = order; |
| 1543 | 1549 | |
| 1544 | | ir_ref_instruction(order_value); |
| 1550 | ir_ref_instruction(order_value, irb->current_basic_block); |
| 1545 | 1551 | |
| 1546 | 1552 | return &instruction->base; |
| 1547 | 1553 | } |
| ... | ... | @@ -1557,8 +1563,8 @@ static IrInstruction *ir_build_div_exact(IrBuilder *irb, Scope *scope, AstNode * |
| 1557 | 1563 | instruction->op1 = op1; |
| 1558 | 1564 | instruction->op2 = op2; |
| 1559 | 1565 | |
| 1560 | | ir_ref_instruction(op1); |
| 1561 | | ir_ref_instruction(op2); |
| 1566 | ir_ref_instruction(op1, irb->current_basic_block); |
| 1567 | ir_ref_instruction(op2, irb->current_basic_block); |
| 1562 | 1568 | |
| 1563 | 1569 | return &instruction->base; |
| 1564 | 1570 | } |
| ... | ... | @@ -1574,8 +1580,8 @@ static IrInstruction *ir_build_truncate(IrBuilder *irb, Scope *scope, AstNode *s |
| 1574 | 1580 | instruction->dest_type = dest_type; |
| 1575 | 1581 | instruction->target = target; |
| 1576 | 1582 | |
| 1577 | | ir_ref_instruction(dest_type); |
| 1578 | | ir_ref_instruction(target); |
| 1583 | ir_ref_instruction(dest_type, irb->current_basic_block); |
| 1584 | ir_ref_instruction(target, irb->current_basic_block); |
| 1579 | 1585 | |
| 1580 | 1586 | return &instruction->base; |
| 1581 | 1587 | } |
| ... | ... | @@ -1591,8 +1597,8 @@ static IrInstruction *ir_build_int_type(IrBuilder *irb, Scope *scope, AstNode *s |
| 1591 | 1597 | instruction->is_signed = is_signed; |
| 1592 | 1598 | instruction->bit_count = bit_count; |
| 1593 | 1599 | |
| 1594 | | ir_ref_instruction(is_signed); |
| 1595 | | ir_ref_instruction(bit_count); |
| 1600 | ir_ref_instruction(is_signed, irb->current_basic_block); |
| 1601 | ir_ref_instruction(bit_count, irb->current_basic_block); |
| 1596 | 1602 | |
| 1597 | 1603 | return &instruction->base; |
| 1598 | 1604 | } |
| ... | ... | @@ -1601,7 +1607,7 @@ static IrInstruction *ir_build_bool_not(IrBuilder *irb, Scope *scope, AstNode *s |
| 1601 | 1607 | IrInstructionBoolNot *instruction = ir_build_instruction<IrInstructionBoolNot>(irb, scope, source_node); |
| 1602 | 1608 | instruction->value = value; |
| 1603 | 1609 | |
| 1604 | | ir_ref_instruction(value); |
| 1610 | ir_ref_instruction(value, irb->current_basic_block); |
| 1605 | 1611 | |
| 1606 | 1612 | return &instruction->base; |
| 1607 | 1613 | } |
| ... | ... | @@ -1619,8 +1625,8 @@ static IrInstruction *ir_build_alloca(IrBuilder *irb, Scope *scope, AstNode *sou |
| 1619 | 1625 | instruction->type_value = type_value; |
| 1620 | 1626 | instruction->count = count; |
| 1621 | 1627 | |
| 1622 | | ir_ref_instruction(type_value); |
| 1623 | | ir_ref_instruction(count); |
| 1628 | ir_ref_instruction(type_value, irb->current_basic_block); |
| 1629 | ir_ref_instruction(count, irb->current_basic_block); |
| 1624 | 1630 | |
| 1625 | 1631 | return &instruction->base; |
| 1626 | 1632 | } |
| ... | ... | @@ -1641,9 +1647,9 @@ static IrInstruction *ir_build_memset(IrBuilder *irb, Scope *scope, AstNode *sou |
| 1641 | 1647 | instruction->byte = byte; |
| 1642 | 1648 | instruction->count = count; |
| 1643 | 1649 | |
| 1644 | | ir_ref_instruction(dest_ptr); |
| 1645 | | ir_ref_instruction(byte); |
| 1646 | | ir_ref_instruction(count); |
| 1650 | ir_ref_instruction(dest_ptr, irb->current_basic_block); |
| 1651 | ir_ref_instruction(byte, irb->current_basic_block); |
| 1652 | ir_ref_instruction(count, irb->current_basic_block); |
| 1647 | 1653 | |
| 1648 | 1654 | return &instruction->base; |
| 1649 | 1655 | } |
| ... | ... | @@ -1664,9 +1670,9 @@ static IrInstruction *ir_build_memcpy(IrBuilder *irb, Scope *scope, AstNode *sou |
| 1664 | 1670 | instruction->src_ptr = src_ptr; |
| 1665 | 1671 | instruction->count = count; |
| 1666 | 1672 | |
| 1667 | | ir_ref_instruction(dest_ptr); |
| 1668 | | ir_ref_instruction(src_ptr); |
| 1669 | | ir_ref_instruction(count); |
| 1673 | ir_ref_instruction(dest_ptr, irb->current_basic_block); |
| 1674 | ir_ref_instruction(src_ptr, irb->current_basic_block); |
| 1675 | ir_ref_instruction(count, irb->current_basic_block); |
| 1670 | 1676 | |
| 1671 | 1677 | return &instruction->base; |
| 1672 | 1678 | } |
| ... | ... | @@ -1689,9 +1695,9 @@ static IrInstruction *ir_build_slice(IrBuilder *irb, Scope *scope, AstNode *sour |
| 1689 | 1695 | instruction->is_const = is_const; |
| 1690 | 1696 | instruction->safety_check_on = safety_check_on; |
| 1691 | 1697 | |
| 1692 | | ir_ref_instruction(ptr); |
| 1693 | | ir_ref_instruction(start); |
| 1694 | | if (end) ir_ref_instruction(end); |
| 1698 | ir_ref_instruction(ptr, irb->current_basic_block); |
| 1699 | ir_ref_instruction(start, irb->current_basic_block); |
| 1700 | if (end) ir_ref_instruction(end, irb->current_basic_block); |
| 1695 | 1701 | |
| 1696 | 1702 | return &instruction->base; |
| 1697 | 1703 | } |
| ... | ... | @@ -1709,7 +1715,7 @@ static IrInstruction *ir_build_member_count(IrBuilder *irb, Scope *scope, AstNod |
| 1709 | 1715 | IrInstructionMemberCount *instruction = ir_build_instruction<IrInstructionMemberCount>(irb, scope, source_node); |
| 1710 | 1716 | instruction->container = container; |
| 1711 | 1717 | |
| 1712 | | ir_ref_instruction(container); |
| 1718 | ir_ref_instruction(container, irb->current_basic_block); |
| 1713 | 1719 | |
| 1714 | 1720 | return &instruction->base; |
| 1715 | 1721 | } |
| ... | ... | @@ -1759,10 +1765,10 @@ static IrInstruction *ir_build_overflow_op(IrBuilder *irb, Scope *scope, AstNode |
| 1759 | 1765 | instruction->result_ptr = result_ptr; |
| 1760 | 1766 | instruction->result_ptr_type = result_ptr_type; |
| 1761 | 1767 | |
| 1762 | | ir_ref_instruction(type_value); |
| 1763 | | ir_ref_instruction(op1); |
| 1764 | | ir_ref_instruction(op2); |
| 1765 | | ir_ref_instruction(result_ptr); |
| 1768 | ir_ref_instruction(type_value, irb->current_basic_block); |
| 1769 | ir_ref_instruction(op1, irb->current_basic_block); |
| 1770 | ir_ref_instruction(op2, irb->current_basic_block); |
| 1771 | ir_ref_instruction(result_ptr, irb->current_basic_block); |
| 1766 | 1772 | |
| 1767 | 1773 | return &instruction->base; |
| 1768 | 1774 | } |
| ... | ... | @@ -1781,7 +1787,7 @@ static IrInstruction *ir_build_alignof(IrBuilder *irb, Scope *scope, AstNode *so |
| 1781 | 1787 | IrInstructionAlignOf *instruction = ir_build_instruction<IrInstructionAlignOf>(irb, scope, source_node); |
| 1782 | 1788 | instruction->type_value = type_value; |
| 1783 | 1789 | |
| 1784 | | ir_ref_instruction(type_value); |
| 1790 | ir_ref_instruction(type_value, irb->current_basic_block); |
| 1785 | 1791 | |
| 1786 | 1792 | return &instruction->base; |
| 1787 | 1793 | } |
| ... | ... | @@ -1792,7 +1798,7 @@ static IrInstruction *ir_build_test_err(IrBuilder *irb, Scope *scope, AstNode *s |
| 1792 | 1798 | IrInstructionTestErr *instruction = ir_build_instruction<IrInstructionTestErr>(irb, scope, source_node); |
| 1793 | 1799 | instruction->value = value; |
| 1794 | 1800 | |
| 1795 | | ir_ref_instruction(value); |
| 1801 | ir_ref_instruction(value, irb->current_basic_block); |
| 1796 | 1802 | |
| 1797 | 1803 | return &instruction->base; |
| 1798 | 1804 | } |
| ... | ... | @@ -1810,7 +1816,7 @@ static IrInstruction *ir_build_unwrap_err_code(IrBuilder *irb, Scope *scope, Ast |
| 1810 | 1816 | IrInstructionUnwrapErrCode *instruction = ir_build_instruction<IrInstructionUnwrapErrCode>(irb, scope, source_node); |
| 1811 | 1817 | instruction->value = value; |
| 1812 | 1818 | |
| 1813 | | ir_ref_instruction(value); |
| 1819 | ir_ref_instruction(value, irb->current_basic_block); |
| 1814 | 1820 | |
| 1815 | 1821 | return &instruction->base; |
| 1816 | 1822 | } |
| ... | ... | @@ -1831,7 +1837,7 @@ static IrInstruction *ir_build_unwrap_err_payload(IrBuilder *irb, Scope *scope, |
| 1831 | 1837 | instruction->value = value; |
| 1832 | 1838 | instruction->safety_check_on = safety_check_on; |
| 1833 | 1839 | |
| 1834 | | ir_ref_instruction(value); |
| 1840 | ir_ref_instruction(value, irb->current_basic_block); |
| 1835 | 1841 | |
| 1836 | 1842 | return &instruction->base; |
| 1837 | 1843 | } |
| ... | ... | @@ -1854,9 +1860,9 @@ static IrInstruction *ir_build_fn_proto(IrBuilder *irb, Scope *scope, AstNode *s |
| 1854 | 1860 | |
| 1855 | 1861 | assert(source_node->type == NodeTypeFnProto); |
| 1856 | 1862 | for (size_t i = 0; i < source_node->data.fn_proto.params.length; i += 1) { |
| 1857 | | ir_ref_instruction(param_types[i]); |
| 1863 | ir_ref_instruction(param_types[i], irb->current_basic_block); |
| 1858 | 1864 | } |
| 1859 | | ir_ref_instruction(return_type); |
| 1865 | ir_ref_instruction(return_type, irb->current_basic_block); |
| 1860 | 1866 | |
| 1861 | 1867 | return &instruction->base; |
| 1862 | 1868 | } |
| ... | ... | @@ -1865,7 +1871,7 @@ static IrInstruction *ir_build_test_comptime(IrBuilder *irb, Scope *scope, AstNo |
| 1865 | 1871 | IrInstructionTestComptime *instruction = ir_build_instruction<IrInstructionTestComptime>(irb, scope, source_node); |
| 1866 | 1872 | instruction->value = value; |
| 1867 | 1873 | |
| 1868 | | ir_ref_instruction(value); |
| 1874 | ir_ref_instruction(value, irb->current_basic_block); |
| 1869 | 1875 | |
| 1870 | 1876 | return &instruction->base; |
| 1871 | 1877 | } |
| ... | ... | @@ -1878,7 +1884,7 @@ static IrInstruction *ir_build_init_enum(IrBuilder *irb, Scope *scope, AstNode * |
| 1878 | 1884 | instruction->field = field; |
| 1879 | 1885 | instruction->init_value = init_value; |
| 1880 | 1886 | |
| 1881 | | ir_ref_instruction(init_value); |
| 1887 | ir_ref_instruction(init_value, irb->current_basic_block); |
| 1882 | 1888 | |
| 1883 | 1889 | return &instruction->base; |
| 1884 | 1890 | } |
| ... | ... | @@ -1899,7 +1905,7 @@ static IrInstruction *ir_build_pointer_reinterpret(IrBuilder *irb, Scope *scope, |
| 1899 | 1905 | irb, scope, source_node); |
| 1900 | 1906 | instruction->ptr = ptr; |
| 1901 | 1907 | |
| 1902 | | ir_ref_instruction(ptr); |
| 1908 | ir_ref_instruction(ptr, irb->current_basic_block); |
| 1903 | 1909 | |
| 1904 | 1910 | return &instruction->base; |
| 1905 | 1911 | } |
| ... | ... | @@ -1911,7 +1917,7 @@ static IrInstruction *ir_build_widen_or_shorten(IrBuilder *irb, Scope *scope, As |
| 1911 | 1917 | irb, scope, source_node); |
| 1912 | 1918 | instruction->target = target; |
| 1913 | 1919 | |
| 1914 | | ir_ref_instruction(target); |
| 1920 | ir_ref_instruction(target, irb->current_basic_block); |
| 1915 | 1921 | |
| 1916 | 1922 | return &instruction->base; |
| 1917 | 1923 | } |
| ... | ... | @@ -1923,7 +1929,7 @@ static IrInstruction *ir_build_int_to_ptr(IrBuilder *irb, Scope *scope, AstNode |
| 1923 | 1929 | irb, scope, source_node); |
| 1924 | 1930 | instruction->target = target; |
| 1925 | 1931 | |
| 1926 | | ir_ref_instruction(target); |
| 1932 | ir_ref_instruction(target, irb->current_basic_block); |
| 1927 | 1933 | |
| 1928 | 1934 | return &instruction->base; |
| 1929 | 1935 | } |
| ... | ... | @@ -1935,7 +1941,7 @@ static IrInstruction *ir_build_ptr_to_int(IrBuilder *irb, Scope *scope, AstNode |
| 1935 | 1941 | irb, scope, source_node); |
| 1936 | 1942 | instruction->target = target; |
| 1937 | 1943 | |
| 1938 | | ir_ref_instruction(target); |
| 1944 | ir_ref_instruction(target, irb->current_basic_block); |
| 1939 | 1945 | |
| 1940 | 1946 | return &instruction->base; |
| 1941 | 1947 | } |
| ... | ... | @@ -1947,7 +1953,7 @@ static IrInstruction *ir_build_int_to_enum(IrBuilder *irb, Scope *scope, AstNode |
| 1947 | 1953 | irb, scope, source_node); |
| 1948 | 1954 | instruction->target = target; |
| 1949 | 1955 | |
| 1950 | | ir_ref_instruction(target); |
| 1956 | ir_ref_instruction(target, irb->current_basic_block); |
| 1951 | 1957 | |
| 1952 | 1958 | return &instruction->base; |
| 1953 | 1959 | } |
| ... | ... | @@ -2736,6 +2742,11 @@ static void ir_count_defers(IrBuilder *irb, Scope *inner_scope, Scope *outer_sco |
| 2736 | 2742 | } |
| 2737 | 2743 | } |
| 2738 | 2744 | |
| 2745 | static IrInstruction *ir_mark_gen(IrInstruction *instruction) { |
| 2746 | instruction->is_gen = true; |
| 2747 | return instruction; |
| 2748 | } |
| 2749 | |
| 2739 | 2750 | static bool ir_gen_defers_for_block(IrBuilder *irb, Scope *inner_scope, Scope *outer_scope, |
| 2740 | 2751 | bool gen_error_defers, bool gen_maybe_defers) |
| 2741 | 2752 | { |
| ... | ... | @@ -2986,6 +2997,29 @@ static VariableTableEntry *ir_create_var(IrBuilder *irb, AstNode *node, Scope *s |
| 2986 | 2997 | return var; |
| 2987 | 2998 | } |
| 2988 | 2999 | |
| 3000 | static LabelTableEntry *find_label(IrExecutable *exec, Scope *scope, Buf *name) { |
| 3001 | while (scope) { |
| 3002 | if (scope->id == ScopeIdBlock) { |
| 3003 | ScopeBlock *block_scope = (ScopeBlock *)scope; |
| 3004 | auto entry = block_scope->label_table.maybe_get(name); |
| 3005 | if (entry) |
| 3006 | return entry->value; |
| 3007 | } |
| 3008 | scope = scope->parent; |
| 3009 | } |
| 3010 | |
| 3011 | return nullptr; |
| 3012 | } |
| 3013 | |
| 3014 | static ScopeBlock *find_block_scope(IrExecutable *exec, Scope *scope) { |
| 3015 | while (scope) { |
| 3016 | if (scope->id == ScopeIdBlock) |
| 3017 | return (ScopeBlock *)scope; |
| 3018 | scope = scope->parent; |
| 3019 | } |
| 3020 | return nullptr; |
| 3021 | } |
| 3022 | |
| 2989 | 3023 | static IrInstruction *ir_gen_block(IrBuilder *irb, Scope *parent_scope, AstNode *block_node) { |
| 2990 | 3024 | assert(block_node->type == NodeTypeBlock); |
| 2991 | 3025 | |
| ... | ... | @@ -3001,6 +3035,43 @@ static IrInstruction *ir_gen_block(IrBuilder *irb, Scope *parent_scope, AstNode |
| 3001 | 3035 | IrInstruction *return_value = nullptr; |
| 3002 | 3036 | for (size_t i = 0; i < block_node->data.block.statements.length; i += 1) { |
| 3003 | 3037 | AstNode *statement_node = block_node->data.block.statements.at(i); |
| 3038 | |
| 3039 | if (statement_node->type == NodeTypeLabel) { |
| 3040 | Buf *label_name = statement_node->data.label.name; |
| 3041 | IrBasicBlock *label_block = ir_build_basic_block(irb, child_scope, buf_ptr(label_name)); |
| 3042 | LabelTableEntry *label = allocate<LabelTableEntry>(1); |
| 3043 | label->decl_node = statement_node; |
| 3044 | label->bb = label_block; |
| 3045 | irb->exec->all_labels.append(label); |
| 3046 | |
| 3047 | LabelTableEntry *existing_label = find_label(irb->exec, child_scope, label_name); |
| 3048 | if (existing_label) { |
| 3049 | ErrorMsg *msg = add_node_error(irb->codegen, statement_node, |
| 3050 | buf_sprintf("duplicate label name '%s'", buf_ptr(label_name))); |
| 3051 | add_error_note(irb->codegen, msg, existing_label->decl_node, buf_sprintf("other label here")); |
| 3052 | return irb->codegen->invalid_instruction; |
| 3053 | } else { |
| 3054 | ScopeBlock *scope_block = find_block_scope(irb->exec, child_scope); |
| 3055 | scope_block->label_table.put(label_name, label); |
| 3056 | } |
| 3057 | |
| 3058 | if (!return_value || !instr_is_unreachable(return_value)) { |
| 3059 | IrInstruction *is_comptime = ir_mark_gen(ir_build_const_bool(irb, child_scope, statement_node, |
| 3060 | ir_should_inline(irb))); |
| 3061 | ir_mark_gen(ir_build_br(irb, child_scope, statement_node, label_block, is_comptime)); |
| 3062 | } |
| 3063 | ir_set_cursor_at_end(irb, label_block); |
| 3064 | |
| 3065 | return_value = nullptr; |
| 3066 | continue; |
| 3067 | } |
| 3068 | |
| 3069 | if (return_value && instr_is_unreachable(return_value)) { |
| 3070 | if (is_node_void_expr(statement_node)) |
| 3071 | continue; |
| 3072 | add_node_error(irb->codegen, statement_node, buf_sprintf("unreachable code")); |
| 3073 | } |
| 3074 | |
| 3004 | 3075 | return_value = ir_gen_node(irb, statement_node, child_scope); |
| 3005 | 3076 | if (statement_node->type == NodeTypeDefer && return_value != irb->codegen->invalid_instruction) { |
| 3006 | 3077 | // defer starts a new scope |
| ... | ... | @@ -3014,9 +3085,10 @@ static IrInstruction *ir_gen_block(IrBuilder *irb, Scope *parent_scope, AstNode |
| 3014 | 3085 | } |
| 3015 | 3086 | |
| 3016 | 3087 | if (!return_value) |
| 3017 | | return_value = ir_build_const_void(irb, child_scope, block_node); |
| 3088 | return_value = ir_mark_gen(ir_build_const_void(irb, child_scope, block_node)); |
| 3018 | 3089 | |
| 3019 | | ir_gen_defers_for_block(irb, child_scope, outer_block_scope, false, false); |
| 3090 | if (!instr_is_unreachable(return_value)) |
| 3091 | ir_gen_defers_for_block(irb, child_scope, outer_block_scope, false, false); |
| 3020 | 3092 | |
| 3021 | 3093 | return return_value; |
| 3022 | 3094 | } |
| ... | ... | @@ -3167,7 +3239,8 @@ static IrInstruction *ir_gen_maybe_ok_or(IrBuilder *irb, Scope *parent_scope, As |
| 3167 | 3239 | if (null_result == irb->codegen->invalid_instruction) |
| 3168 | 3240 | return irb->codegen->invalid_instruction; |
| 3169 | 3241 | IrBasicBlock *after_null_block = irb->current_basic_block; |
| 3170 | | ir_build_br(irb, parent_scope, node, end_block, is_comptime); |
| 3242 | if (!instr_is_unreachable(null_result)) |
| 3243 | ir_mark_gen(ir_build_br(irb, parent_scope, node, end_block, is_comptime)); |
| 3171 | 3244 | |
| 3172 | 3245 | ir_set_cursor_at_end(irb, ok_block); |
| 3173 | 3246 | IrInstruction *unwrapped_ptr = ir_build_unwrap_maybe(irb, parent_scope, node, maybe_ptr, false); |
| ... | ... | @@ -3886,7 +3959,7 @@ static IrInstruction *ir_gen_fn_call(IrBuilder *irb, Scope *scope, AstNode *node |
| 3886 | 3959 | } |
| 3887 | 3960 | |
| 3888 | 3961 | bool is_comptime = node->data.fn_call_expr.is_comptime; |
| 3889 | | return ir_build_call(irb, scope, node, nullptr, fn_ref, arg_count, args, is_comptime); |
| 3962 | return ir_mark_gen(ir_build_call(irb, scope, node, nullptr, fn_ref, arg_count, args, is_comptime)); |
| 3890 | 3963 | } |
| 3891 | 3964 | |
| 3892 | 3965 | static IrInstruction *ir_gen_if_bool_expr(IrBuilder *irb, Scope *scope, AstNode *node) { |
| ... | ... | @@ -3917,7 +3990,8 @@ static IrInstruction *ir_gen_if_bool_expr(IrBuilder *irb, Scope *scope, AstNode |
| 3917 | 3990 | if (then_expr_result == irb->codegen->invalid_instruction) |
| 3918 | 3991 | return then_expr_result; |
| 3919 | 3992 | IrBasicBlock *after_then_block = irb->current_basic_block; |
| 3920 | | ir_build_br(irb, scope, node, endif_block, is_comptime); |
| 3993 | if (!instr_is_unreachable(then_expr_result)) |
| 3994 | ir_mark_gen(ir_build_br(irb, scope, node, endif_block, is_comptime)); |
| 3921 | 3995 | |
| 3922 | 3996 | ir_set_cursor_at_end(irb, else_block); |
| 3923 | 3997 | IrInstruction *else_expr_result; |
| ... | ... | @@ -3929,7 +4003,8 @@ static IrInstruction *ir_gen_if_bool_expr(IrBuilder *irb, Scope *scope, AstNode |
| 3929 | 4003 | else_expr_result = ir_build_const_void(irb, scope, node); |
| 3930 | 4004 | } |
| 3931 | 4005 | IrBasicBlock *after_else_block = irb->current_basic_block; |
| 3932 | | ir_build_br(irb, scope, node, endif_block, is_comptime); |
| 4006 | if (!instr_is_unreachable(else_expr_result)) |
| 4007 | ir_mark_gen(ir_build_br(irb, scope, node, endif_block, is_comptime)); |
| 3933 | 4008 | |
| 3934 | 4009 | ir_set_cursor_at_end(irb, endif_block); |
| 3935 | 4010 | IrInstruction **incoming_values = allocate<IrInstruction *>(2); |
| ... | ... | @@ -4158,13 +4233,17 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 4158 | 4233 | |
| 4159 | 4234 | if (continue_expr_node) { |
| 4160 | 4235 | ir_set_cursor_at_end(irb, continue_block); |
| 4161 | | ir_gen_node(irb, continue_expr_node, scope); |
| 4162 | | ir_build_br(irb, scope, node, cond_block, is_comptime); |
| 4236 | IrInstruction *expr_result = ir_gen_node(irb, continue_expr_node, scope); |
| 4237 | if (!instr_is_unreachable(expr_result)) |
| 4238 | ir_mark_gen(ir_build_br(irb, scope, node, cond_block, is_comptime)); |
| 4163 | 4239 | } |
| 4164 | 4240 | |
| 4165 | 4241 | ir_set_cursor_at_end(irb, cond_block); |
| 4166 | 4242 | IrInstruction *cond_val = ir_gen_node(irb, node->data.while_expr.condition, scope); |
| 4167 | | ir_build_cond_br(irb, scope, node->data.while_expr.condition, cond_val, body_block, end_block, is_comptime); |
| 4243 | if (!instr_is_unreachable(cond_val)) { |
| 4244 | ir_mark_gen(ir_build_cond_br(irb, scope, node->data.while_expr.condition, cond_val, |
| 4245 | body_block, end_block, is_comptime)); |
| 4246 | } |
| 4168 | 4247 | |
| 4169 | 4248 | ir_set_cursor_at_end(irb, body_block); |
| 4170 | 4249 | |
| ... | ... | @@ -4172,10 +4251,11 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 4172 | 4251 | loop_stack_item->break_block = end_block; |
| 4173 | 4252 | loop_stack_item->continue_block = continue_block; |
| 4174 | 4253 | loop_stack_item->is_comptime = is_comptime; |
| 4175 | | ir_gen_node(irb, node->data.while_expr.body, scope); |
| 4254 | IrInstruction *body_result = ir_gen_node(irb, node->data.while_expr.body, scope); |
| 4176 | 4255 | irb->loop_stack.pop(); |
| 4177 | 4256 | |
| 4178 | | ir_build_br(irb, scope, node, continue_block, is_comptime); |
| 4257 | if (!instr_is_unreachable(body_result)) |
| 4258 | ir_mark_gen(ir_build_br(irb, scope, node, continue_block, is_comptime)); |
| 4179 | 4259 | ir_set_cursor_at_end(irb, end_block); |
| 4180 | 4260 | |
| 4181 | 4261 | return ir_build_const_void(irb, scope, node); |
| ... | ... | @@ -4270,10 +4350,11 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo |
| 4270 | 4350 | loop_stack_item->break_block = end_block; |
| 4271 | 4351 | loop_stack_item->continue_block = continue_block; |
| 4272 | 4352 | loop_stack_item->is_comptime = is_comptime; |
| 4273 | | ir_gen_node(irb, body_node, child_scope); |
| 4353 | IrInstruction *body_result = ir_gen_node(irb, body_node, child_scope); |
| 4274 | 4354 | irb->loop_stack.pop(); |
| 4275 | 4355 | |
| 4276 | | ir_build_br(irb, child_scope, node, continue_block, is_comptime); |
| 4356 | if (!instr_is_unreachable(body_result)) |
| 4357 | ir_mark_gen(ir_build_br(irb, child_scope, node, continue_block, is_comptime)); |
| 4277 | 4358 | |
| 4278 | 4359 | ir_set_cursor_at_end(irb, continue_block); |
| 4279 | 4360 | IrInstruction *new_index_val = ir_build_bin_op(irb, child_scope, node, IrBinOpAdd, index_val, one, false); |
| ... | ... | @@ -4457,7 +4538,8 @@ static IrInstruction *ir_gen_if_var_expr(IrBuilder *irb, Scope *scope, AstNode * |
| 4457 | 4538 | if (then_expr_result == irb->codegen->invalid_instruction) |
| 4458 | 4539 | return then_expr_result; |
| 4459 | 4540 | IrBasicBlock *after_then_block = irb->current_basic_block; |
| 4460 | | ir_build_br(irb, scope, node, endif_block, is_comptime); |
| 4541 | if (!instr_is_unreachable(then_expr_result)) |
| 4542 | ir_mark_gen(ir_build_br(irb, scope, node, endif_block, is_comptime)); |
| 4461 | 4543 | |
| 4462 | 4544 | ir_set_cursor_at_end(irb, else_block); |
| 4463 | 4545 | IrInstruction *else_expr_result; |
| ... | ... | @@ -4469,7 +4551,8 @@ static IrInstruction *ir_gen_if_var_expr(IrBuilder *irb, Scope *scope, AstNode * |
| 4469 | 4551 | else_expr_result = ir_build_const_void(irb, scope, node); |
| 4470 | 4552 | } |
| 4471 | 4553 | IrBasicBlock *after_else_block = irb->current_basic_block; |
| 4472 | | ir_build_br(irb, scope, node, endif_block, is_comptime); |
| 4554 | if (!instr_is_unreachable(else_expr_result)) |
| 4555 | ir_mark_gen(ir_build_br(irb, scope, node, endif_block, is_comptime)); |
| 4473 | 4556 | |
| 4474 | 4557 | ir_set_cursor_at_end(irb, endif_block); |
| 4475 | 4558 | IrInstruction **incoming_values = allocate<IrInstruction *>(2); |
| ... | ... | @@ -4518,7 +4601,8 @@ static bool ir_gen_switch_prong_expr(IrBuilder *irb, Scope *scope, AstNode *swit |
| 4518 | 4601 | IrInstruction *expr_result = ir_gen_node(irb, expr_node, child_scope); |
| 4519 | 4602 | if (expr_result == irb->codegen->invalid_instruction) |
| 4520 | 4603 | return false; |
| 4521 | | ir_build_br(irb, scope, switch_node, end_block, is_comptime); |
| 4604 | if (!instr_is_unreachable(expr_result)) |
| 4605 | ir_mark_gen(ir_build_br(irb, scope, switch_node, end_block, is_comptime)); |
| 4522 | 4606 | incoming_blocks->append(irb->current_basic_block); |
| 4523 | 4607 | incoming_values->append(expr_result); |
| 4524 | 4608 | return true; |
| ... | ... | @@ -4684,57 +4768,6 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode * |
| 4684 | 4768 | return ir_build_phi(irb, scope, node, incoming_blocks.length, incoming_blocks.items, incoming_values.items); |
| 4685 | 4769 | } |
| 4686 | 4770 | |
| 4687 | | static LabelTableEntry *find_label(IrExecutable *exec, Scope *scope, Buf *name) { |
| 4688 | | while (scope) { |
| 4689 | | if (scope->id == ScopeIdBlock) { |
| 4690 | | ScopeBlock *block_scope = (ScopeBlock *)scope; |
| 4691 | | auto entry = block_scope->label_table.maybe_get(name); |
| 4692 | | if (entry) |
| 4693 | | return entry->value; |
| 4694 | | } |
| 4695 | | scope = scope->parent; |
| 4696 | | } |
| 4697 | | |
| 4698 | | return nullptr; |
| 4699 | | } |
| 4700 | | |
| 4701 | | static ScopeBlock *find_block_scope(IrExecutable *exec, Scope *scope) { |
| 4702 | | while (scope) { |
| 4703 | | if (scope->id == ScopeIdBlock) |
| 4704 | | return (ScopeBlock *)scope; |
| 4705 | | scope = scope->parent; |
| 4706 | | } |
| 4707 | | return nullptr; |
| 4708 | | } |
| 4709 | | |
| 4710 | | static IrInstruction *ir_gen_label(IrBuilder *irb, Scope *scope, AstNode *node) { |
| 4711 | | assert(node->type == NodeTypeLabel); |
| 4712 | | |
| 4713 | | Buf *label_name = node->data.label.name; |
| 4714 | | IrBasicBlock *label_block = ir_build_basic_block(irb, scope, buf_ptr(label_name)); |
| 4715 | | LabelTableEntry *label = allocate<LabelTableEntry>(1); |
| 4716 | | label->decl_node = node; |
| 4717 | | label->bb = label_block; |
| 4718 | | irb->exec->all_labels.append(label); |
| 4719 | | |
| 4720 | | LabelTableEntry *existing_label = find_label(irb->exec, scope, label_name); |
| 4721 | | if (existing_label) { |
| 4722 | | ErrorMsg *msg = add_node_error(irb->codegen, node, |
| 4723 | | buf_sprintf("duplicate label name '%s'", buf_ptr(label_name))); |
| 4724 | | add_error_note(irb->codegen, msg, existing_label->decl_node, buf_sprintf("other label here")); |
| 4725 | | return irb->codegen->invalid_instruction; |
| 4726 | | } else { |
| 4727 | | ScopeBlock *scope_block = find_block_scope(irb->exec, scope); |
| 4728 | | scope_block->label_table.put(label_name, label); |
| 4729 | | } |
| 4730 | | |
| 4731 | | IrInstruction *is_comptime = ir_build_const_bool(irb, scope, node, |
| 4732 | | ir_should_inline(irb)); |
| 4733 | | ir_build_br(irb, scope, node, label_block, is_comptime); |
| 4734 | | ir_set_cursor_at_end(irb, label_block); |
| 4735 | | return ir_build_const_void(irb, scope, node); |
| 4736 | | } |
| 4737 | | |
| 4738 | 4771 | static IrInstruction *ir_gen_goto(IrBuilder *irb, Scope *scope, AstNode *node) { |
| 4739 | 4772 | assert(node->type == NodeTypeGoto); |
| 4740 | 4773 | |
| ... | ... | @@ -4894,7 +4927,8 @@ static IrInstruction *ir_gen_err_ok_or(IrBuilder *irb, Scope *parent_scope, AstN |
| 4894 | 4927 | if (err_result == irb->codegen->invalid_instruction) |
| 4895 | 4928 | return irb->codegen->invalid_instruction; |
| 4896 | 4929 | IrBasicBlock *after_err_block = irb->current_basic_block; |
| 4897 | | ir_build_br(irb, err_scope, node, end_block, is_comptime); |
| 4930 | if (!instr_is_unreachable(err_result)) |
| 4931 | ir_mark_gen(ir_build_br(irb, err_scope, node, end_block, is_comptime)); |
| 4898 | 4932 | |
| 4899 | 4933 | ir_set_cursor_at_end(irb, ok_block); |
| 4900 | 4934 | IrInstruction *unwrapped_ptr = ir_build_unwrap_err_payload(irb, parent_scope, node, err_union_ptr, false); |
| ... | ... | @@ -4989,6 +5023,7 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop |
| 4989 | 5023 | case NodeTypeSwitchProng: |
| 4990 | 5024 | case NodeTypeSwitchRange: |
| 4991 | 5025 | case NodeTypeStructField: |
| 5026 | case NodeTypeLabel: |
| 4992 | 5027 | zig_unreachable(); |
| 4993 | 5028 | case NodeTypeBlock: |
| 4994 | 5029 | return ir_lval_wrap(irb, scope, ir_gen_block(irb, scope, node), lval); |
| ... | ... | @@ -5040,8 +5075,6 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop |
| 5040 | 5075 | return ir_lval_wrap(irb, scope, ir_gen_if_var_expr(irb, scope, node), lval); |
| 5041 | 5076 | case NodeTypeSwitchExpr: |
| 5042 | 5077 | return ir_lval_wrap(irb, scope, ir_gen_switch_expr(irb, scope, node), lval); |
| 5043 | | case NodeTypeLabel: |
| 5044 | | return ir_lval_wrap(irb, scope, ir_gen_label(irb, scope, node), lval); |
| 5045 | 5078 | case NodeTypeGoto: |
| 5046 | 5079 | return ir_lval_wrap(irb, scope, ir_gen_goto(irb, scope, node), lval); |
| 5047 | 5080 | case NodeTypeTypeLiteral: |
| ... | ... | @@ -5130,7 +5163,7 @@ static bool ir_goto_pass2(IrBuilder *irb) { |
| 5130 | 5163 | return true; |
| 5131 | 5164 | } |
| 5132 | 5165 | |
| 5133 | | IrInstruction *ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_executable) { |
| 5166 | bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_executable) { |
| 5134 | 5167 | assert(node->owner); |
| 5135 | 5168 | |
| 5136 | 5169 | IrBuilder ir_builder = {0}; |
| ... | ... | @@ -5146,20 +5179,21 @@ IrInstruction *ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutabl |
| 5146 | 5179 | IrInstruction *result = ir_gen_node_extra(irb, node, scope, LValPurposeNone); |
| 5147 | 5180 | assert(result); |
| 5148 | 5181 | if (irb->exec->invalid) |
| 5149 | | return codegen->invalid_instruction; |
| 5182 | return false; |
| 5150 | 5183 | |
| 5151 | | IrInstruction *return_instruction = ir_build_return(irb, scope, result->source_node, result); |
| 5152 | | assert(return_instruction); |
| 5184 | if (!instr_is_unreachable(result)) { |
| 5185 | ir_mark_gen(ir_build_return(irb, scope, result->source_node, result)); |
| 5186 | } |
| 5153 | 5187 | |
| 5154 | 5188 | if (!ir_goto_pass2(irb)) { |
| 5155 | 5189 | irb->exec->invalid = true; |
| 5156 | | return codegen->invalid_instruction; |
| 5190 | return false; |
| 5157 | 5191 | } |
| 5158 | 5192 | |
| 5159 | | return return_instruction; |
| 5193 | return true; |
| 5160 | 5194 | } |
| 5161 | 5195 | |
| 5162 | | IrInstruction *ir_gen_fn(CodeGen *codegen, FnTableEntry *fn_entry) { |
| 5196 | bool ir_gen_fn(CodeGen *codegen, FnTableEntry *fn_entry) { |
| 5163 | 5197 | assert(fn_entry); |
| 5164 | 5198 | |
| 5165 | 5199 | IrExecutable *ir_executable = &fn_entry->ir_executable; |
| ... | ... | @@ -5622,6 +5656,16 @@ static void ir_start_bb(IrAnalyze *ira, IrBasicBlock *old_bb, IrBasicBlock *cons |
| 5622 | 5656 | } |
| 5623 | 5657 | |
| 5624 | 5658 | static void ir_finish_bb(IrAnalyze *ira) { |
| 5659 | ira->instruction_index += 1; |
| 5660 | while (ira->instruction_index < ira->old_irb.current_basic_block->instruction_list.length) { |
| 5661 | IrInstruction *next_instruction = ira->old_irb.current_basic_block->instruction_list.at(ira->instruction_index); |
| 5662 | if (!next_instruction->is_gen) { |
| 5663 | ir_add_error(ira, next_instruction, buf_sprintf("unreachable code")); |
| 5664 | break; |
| 5665 | } |
| 5666 | ira->instruction_index += 1; |
| 5667 | } |
| 5668 | |
| 5625 | 5669 | ira->block_queue_index += 1; |
| 5626 | 5670 | |
| 5627 | 5671 | if (ira->block_queue_index < ira->old_bb_queue.length) { |
| ... | ... | @@ -5711,6 +5755,11 @@ static TypeTableEntry *ir_analyze_const_ptr(IrAnalyze *ira, IrInstruction *instr |
| 5711 | 5755 | { |
| 5712 | 5756 | if (pointee_type->id == TypeTableEntryIdMetaType) { |
| 5713 | 5757 | TypeTableEntry *type_entry = pointee->data.x_type; |
| 5758 | if (type_entry->id == TypeTableEntryIdUnreachable) { |
| 5759 | ir_add_error(ira, instruction, buf_sprintf("pointer to unreachable not allowed")); |
| 5760 | return ira->codegen->builtin_types.entry_invalid; |
| 5761 | } |
| 5762 | |
| 5714 | 5763 | ConstExprValue *const_val = ir_build_const_from(ira, instruction, |
| 5715 | 5764 | depends_on_compile_var || pointee->depends_on_compile_var); |
| 5716 | 5765 | type_ensure_zero_bits_known(ira->codegen, type_entry); |
| ... | ... | @@ -7903,6 +7952,10 @@ static TypeTableEntry *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstruct |
| 7903 | 7952 | |
| 7904 | 7953 | if (is_comptime || old_dest_block->ref_count == 1) |
| 7905 | 7954 | return ir_inline_bb(ira, &cond_br_instruction->base, old_dest_block); |
| 7955 | |
| 7956 | IrBasicBlock *new_dest_block = ir_get_new_bb(ira, old_dest_block); |
| 7957 | ir_build_br_from(&ira->new_irb, &cond_br_instruction->base, new_dest_block); |
| 7958 | return ir_finish_anal(ira, ira->codegen->builtin_types.entry_unreachable); |
| 7906 | 7959 | } |
| 7907 | 7960 | |
| 7908 | 7961 | TypeTableEntry *bool_type = ira->codegen->builtin_types.entry_bool; |