| ... | ... | @@ -227,7 +227,7 @@ static IrInstGen *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name |
| 227 | 227 | static void ir_assert(bool ok, IrInst* source_instruction); |
| 228 | 228 | static void ir_assert_gen(bool ok, IrInstGen *source_instruction); |
| 229 | 229 | static IrInstGen *ir_get_var_ptr(IrAnalyze *ira, IrInst *source_instr, ZigVar *var); |
| 230 | | static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstGen *op, ZigType **actual_type); |
| 230 | static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstGen *op); |
| 231 | 231 | static IrInstSrc *ir_lval_wrap(IrBuilderSrc *irb, Scope *scope, IrInstSrc *value, LVal lval, ResultLoc *result_loc); |
| 232 | 232 | static IrInstSrc *ir_expr_wrap(IrBuilderSrc *irb, Scope *scope, IrInstSrc *inst, ResultLoc *result_loc); |
| 233 | 233 | static ZigType *adjust_ptr_align(CodeGen *g, ZigType *ptr_type, uint32_t new_align); |
| ... | ... | @@ -3406,7 +3406,7 @@ static IrInstSrc *ir_build_cmpxchg_src(IrBuilderSrc *irb, Scope *scope, AstNode |
| 3406 | 3406 | |
| 3407 | 3407 | static IrInstGen *ir_build_cmpxchg_gen(IrAnalyze *ira, IrInst *source_instruction, ZigType *result_type, |
| 3408 | 3408 | IrInstGen *ptr, IrInstGen *cmp_value, IrInstGen *new_value, |
| 3409 | | AtomicOrder success_order, AtomicOrder failure_order, bool is_weak, IrInstGen *result_loc, ZigType *actual_type) |
| 3409 | AtomicOrder success_order, AtomicOrder failure_order, bool is_weak, IrInstGen *result_loc) |
| 3410 | 3410 | { |
| 3411 | 3411 | IrInstGenCmpxchg *instruction = ir_build_inst_gen<IrInstGenCmpxchg>(&ira->new_irb, |
| 3412 | 3412 | source_instruction->scope, source_instruction->source_node); |
| ... | ... | @@ -3418,7 +3418,6 @@ static IrInstGen *ir_build_cmpxchg_gen(IrAnalyze *ira, IrInst *source_instructio |
| 3418 | 3418 | instruction->failure_order = failure_order; |
| 3419 | 3419 | instruction->is_weak = is_weak; |
| 3420 | 3420 | instruction->result_loc = result_loc; |
| 3421 | | instruction->actual_type = actual_type; |
| 3422 | 3421 | |
| 3423 | 3422 | ir_ref_inst_gen(ptr, ira->new_irb.current_basic_block); |
| 3424 | 3423 | ir_ref_inst_gen(cmp_value, ira->new_irb.current_basic_block); |
| ... | ... | @@ -4555,7 +4554,7 @@ static IrInstSrc *ir_build_atomic_rmw_src(IrBuilderSrc *irb, Scope *scope, AstNo |
| 4555 | 4554 | } |
| 4556 | 4555 | |
| 4557 | 4556 | static IrInstGen *ir_build_atomic_rmw_gen(IrAnalyze *ira, IrInst *source_instr, |
| 4558 | | IrInstGen *ptr, IrInstGen *operand, AtomicRmwOp op, AtomicOrder ordering, ZigType *operand_type, ZigType *actual_type) |
| 4557 | IrInstGen *ptr, IrInstGen *operand, AtomicRmwOp op, AtomicOrder ordering, ZigType *operand_type) |
| 4559 | 4558 | { |
| 4560 | 4559 | IrInstGenAtomicRmw *instruction = ir_build_inst_gen<IrInstGenAtomicRmw>(&ira->new_irb, source_instr->scope, source_instr->source_node); |
| 4561 | 4560 | instruction->base.value->type = operand_type; |
| ... | ... | @@ -4563,7 +4562,6 @@ static IrInstGen *ir_build_atomic_rmw_gen(IrAnalyze *ira, IrInst *source_instr, |
| 4563 | 4562 | instruction->op = op; |
| 4564 | 4563 | instruction->operand = operand; |
| 4565 | 4564 | instruction->ordering = ordering; |
| 4566 | | instruction->actual_type = actual_type; |
| 4567 | 4565 | |
| 4568 | 4566 | ir_ref_inst_gen(ptr, ira->new_irb.current_basic_block); |
| 4569 | 4567 | ir_ref_inst_gen(operand, ira->new_irb.current_basic_block); |
| ... | ... | @@ -4587,14 +4585,13 @@ static IrInstSrc *ir_build_atomic_load_src(IrBuilderSrc *irb, Scope *scope, AstN |
| 4587 | 4585 | } |
| 4588 | 4586 | |
| 4589 | 4587 | static IrInstGen *ir_build_atomic_load_gen(IrAnalyze *ira, IrInst *source_instr, |
| 4590 | | IrInstGen *ptr, AtomicOrder ordering, ZigType *operand_type, ZigType *actual_type) |
| 4588 | IrInstGen *ptr, AtomicOrder ordering, ZigType *operand_type) |
| 4591 | 4589 | { |
| 4592 | 4590 | IrInstGenAtomicLoad *instruction = ir_build_inst_gen<IrInstGenAtomicLoad>(&ira->new_irb, |
| 4593 | 4591 | source_instr->scope, source_instr->source_node); |
| 4594 | 4592 | instruction->base.value->type = operand_type; |
| 4595 | 4593 | instruction->ptr = ptr; |
| 4596 | 4594 | instruction->ordering = ordering; |
| 4597 | | instruction->actual_type = actual_type; |
| 4598 | 4595 | |
| 4599 | 4596 | ir_ref_inst_gen(ptr, ira->new_irb.current_basic_block); |
| 4600 | 4597 | |
| ... | ... | @@ -4619,14 +4616,13 @@ static IrInstSrc *ir_build_atomic_store_src(IrBuilderSrc *irb, Scope *scope, Ast |
| 4619 | 4616 | } |
| 4620 | 4617 | |
| 4621 | 4618 | static IrInstGen *ir_build_atomic_store_gen(IrAnalyze *ira, IrInst *source_instr, |
| 4622 | | IrInstGen *ptr, IrInstGen *value, AtomicOrder ordering, ZigType *actual_type) |
| 4619 | IrInstGen *ptr, IrInstGen *value, AtomicOrder ordering) |
| 4623 | 4620 | { |
| 4624 | 4621 | IrInstGenAtomicStore *instruction = ir_build_inst_void<IrInstGenAtomicStore>(&ira->new_irb, |
| 4625 | 4622 | source_instr->scope, source_instr->source_node); |
| 4626 | 4623 | instruction->ptr = ptr; |
| 4627 | 4624 | instruction->value = value; |
| 4628 | 4625 | instruction->ordering = ordering; |
| 4629 | | instruction->actual_type = actual_type; |
| 4630 | 4626 | |
| 4631 | 4627 | ir_ref_inst_gen(ptr, ira->new_irb.current_basic_block); |
| 4632 | 4628 | ir_ref_inst_gen(value, ira->new_irb.current_basic_block); |
| ... | ... | @@ -25125,8 +25121,7 @@ static IrInstGen *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstSrcEmb |
| 25125 | 25121 | } |
| 25126 | 25122 | |
| 25127 | 25123 | static IrInstGen *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstSrcCmpxchg *instruction) { |
| 25128 | | ZigType *actual_type; |
| 25129 | | ZigType *operand_type = ir_resolve_atomic_operand_type(ira, instruction->type_value->child, &actual_type); |
| 25124 | ZigType *operand_type = ir_resolve_atomic_operand_type(ira, instruction->type_value->child); |
| 25130 | 25125 | if (type_is_invalid(operand_type)) |
| 25131 | 25126 | return ira->codegen->invalid_inst_gen; |
| 25132 | 25127 | |
| ... | ... | @@ -25203,29 +25198,34 @@ static IrInstGen *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstSrcCmpxch |
| 25203 | 25198 | |
| 25204 | 25199 | // special case zero bit types |
| 25205 | 25200 | if (type_has_one_possible_value(ira->codegen, operand_type) == OnePossibleValueYes) { |
| 25206 | | ZigValue *val = ira->codegen->pass1_arena->allocate<ZigValue>(1); |
| 25207 | | val->special = ConstValSpecialStatic; |
| 25208 | | val->type = result_type; |
| 25209 | | set_optional_value_to_null(val); |
| 25210 | | return ir_const_move(ira, &instruction->base.base, val); |
| 25201 | IrInstGen *result = ir_const(ira, &instruction->base.base, result_type); |
| 25202 | set_optional_value_to_null(result->value); |
| 25203 | return result; |
| 25211 | 25204 | } |
| 25212 | 25205 | |
| 25213 | 25206 | if (instr_is_comptime(casted_ptr) && casted_ptr->value->data.x_ptr.mut != ConstPtrMutRuntimeVar && |
| 25214 | 25207 | instr_is_comptime(casted_cmp_value) && instr_is_comptime(casted_new_value)) { |
| 25215 | | IrInstGen *result = ir_get_deref(ira, &instruction->base.base, casted_ptr, nullptr); |
| 25216 | | ZigValue *op1_val = ir_resolve_const(ira, result, UndefBad); |
| 25208 | ZigValue *ptr_val = ir_resolve_const(ira, casted_ptr, UndefBad); |
| 25209 | if (ptr_val == nullptr) |
| 25210 | return ira->codegen->invalid_inst_gen; |
| 25211 | |
| 25212 | ZigValue *op1_val = const_ptr_pointee(ira, ira->codegen, ptr_val, instruction->base.base.source_node); |
| 25213 | if (op1_val == nullptr) |
| 25214 | return ira->codegen->invalid_inst_gen; |
| 25215 | |
| 25217 | 25216 | ZigValue *op2_val = ir_resolve_const(ira, casted_cmp_value, UndefBad); |
| 25217 | if (op2_val == nullptr) |
| 25218 | return ira->codegen->invalid_inst_gen; |
| 25219 | |
| 25218 | 25220 | bool eql = const_values_equal(ira->codegen, op1_val, op2_val); |
| 25219 | | ZigValue *val = ira->codegen->pass1_arena->allocate<ZigValue>(1); |
| 25220 | | val->special = ConstValSpecialStatic; |
| 25221 | | val->type = result_type; |
| 25221 | IrInstGen *result = ir_const(ira, &instruction->base.base, result_type); |
| 25222 | 25222 | if (eql) { |
| 25223 | 25223 | ir_analyze_store_ptr(ira, &instruction->base.base, casted_ptr, casted_new_value, false); |
| 25224 | | set_optional_value_to_null(val); |
| 25224 | set_optional_value_to_null(result->value); |
| 25225 | 25225 | } else { |
| 25226 | | set_optional_payload(val, op1_val); |
| 25226 | set_optional_payload(result->value, op1_val); |
| 25227 | 25227 | } |
| 25228 | | return ir_const_move(ira, &instruction->base.base, val); |
| 25228 | return result; |
| 25229 | 25229 | } |
| 25230 | 25230 | |
| 25231 | 25231 | IrInstGen *result_loc; |
| ... | ... | @@ -25241,7 +25241,7 @@ static IrInstGen *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstSrcCmpxch |
| 25241 | 25241 | |
| 25242 | 25242 | return ir_build_cmpxchg_gen(ira, &instruction->base.base, result_type, |
| 25243 | 25243 | casted_ptr, casted_cmp_value, casted_new_value, |
| 25244 | | success_order, failure_order, instruction->is_weak, result_loc, actual_type); |
| 25244 | success_order, failure_order, instruction->is_weak, result_loc); |
| 25245 | 25245 | } |
| 25246 | 25246 | |
| 25247 | 25247 | static IrInstGen *ir_analyze_instruction_fence(IrAnalyze *ira, IrInstSrcFence *instruction) { |
| ... | ... | @@ -28333,12 +28333,11 @@ static IrInstGen *ir_analyze_instruction_tag_type(IrAnalyze *ira, IrInstSrcTagTy |
| 28333 | 28333 | } |
| 28334 | 28334 | } |
| 28335 | 28335 | |
| 28336 | | static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstGen *op, ZigType **actual_type) { |
| 28336 | static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstGen *op) { |
| 28337 | 28337 | ZigType *operand_type = ir_resolve_type(ira, op); |
| 28338 | 28338 | if (type_is_invalid(operand_type)) |
| 28339 | 28339 | return ira->codegen->builtin_types.entry_invalid; |
| 28340 | 28340 | |
| 28341 | | *actual_type = nullptr; |
| 28342 | 28341 | if (operand_type->id == ZigTypeIdInt || operand_type->id == ZigTypeIdEnum) { |
| 28343 | 28342 | ZigType *int_type; |
| 28344 | 28343 | if (operand_type->id == ZigTypeIdEnum) { |
| ... | ... | @@ -28355,10 +28354,6 @@ static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstGen *op, Zi |
| 28355 | 28354 | max_atomic_bits, bit_count)); |
| 28356 | 28355 | return ira->codegen->builtin_types.entry_invalid; |
| 28357 | 28356 | } |
| 28358 | | |
| 28359 | | if (bit_count == 1 || !is_power_of_2(bit_count)) { |
| 28360 | | *actual_type = get_int_type(ira->codegen, int_type->data.integral.is_signed, int_type->abi_size * 8); |
| 28361 | | } |
| 28362 | 28357 | } else if (operand_type->id == ZigTypeIdFloat) { |
| 28363 | 28358 | uint32_t max_atomic_bits = target_arch_largest_atomic_bits(ira->codegen->zig_target->arch); |
| 28364 | 28359 | if (operand_type->data.floating.bit_count > max_atomic_bits) { |
| ... | ... | @@ -28369,7 +28364,6 @@ static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstGen *op, Zi |
| 28369 | 28364 | } |
| 28370 | 28365 | } else if (operand_type->id == ZigTypeIdBool) { |
| 28371 | 28366 | // will be treated as u8 |
| 28372 | | *actual_type = ira->codegen->builtin_types.entry_u8; |
| 28373 | 28367 | } else { |
| 28374 | 28368 | Error err; |
| 28375 | 28369 | ZigType *operand_ptr_type; |
| ... | ... | @@ -28387,8 +28381,7 @@ static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstGen *op, Zi |
| 28387 | 28381 | } |
| 28388 | 28382 | |
| 28389 | 28383 | static IrInstGen *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstSrcAtomicRmw *instruction) { |
| 28390 | | ZigType *actual_type; |
| 28391 | | ZigType *operand_type = ir_resolve_atomic_operand_type(ira, instruction->operand_type->child, &actual_type); |
| 28384 | ZigType *operand_type = ir_resolve_atomic_operand_type(ira, instruction->operand_type->child); |
| 28392 | 28385 | if (type_is_invalid(operand_type)) |
| 28393 | 28386 | return ira->codegen->invalid_inst_gen; |
| 28394 | 28387 | |
| ... | ... | @@ -28451,12 +28444,11 @@ static IrInstGen *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstSrcAto |
| 28451 | 28444 | } |
| 28452 | 28445 | |
| 28453 | 28446 | return ir_build_atomic_rmw_gen(ira, &instruction->base.base, casted_ptr, casted_operand, op, |
| 28454 | | ordering, operand_type, actual_type); |
| 28447 | ordering, operand_type); |
| 28455 | 28448 | } |
| 28456 | 28449 | |
| 28457 | 28450 | static IrInstGen *ir_analyze_instruction_atomic_load(IrAnalyze *ira, IrInstSrcAtomicLoad *instruction) { |
| 28458 | | ZigType *actual_type; |
| 28459 | | ZigType *operand_type = ir_resolve_atomic_operand_type(ira, instruction->operand_type->child, &actual_type); |
| 28451 | ZigType *operand_type = ir_resolve_atomic_operand_type(ira, instruction->operand_type->child); |
| 28460 | 28452 | if (type_is_invalid(operand_type)) |
| 28461 | 28453 | return ira->codegen->invalid_inst_gen; |
| 28462 | 28454 | |
| ... | ... | @@ -28486,12 +28478,11 @@ static IrInstGen *ir_analyze_instruction_atomic_load(IrAnalyze *ira, IrInstSrcAt |
| 28486 | 28478 | return result; |
| 28487 | 28479 | } |
| 28488 | 28480 | |
| 28489 | | return ir_build_atomic_load_gen(ira, &instruction->base.base, casted_ptr, ordering, operand_type, actual_type); |
| 28481 | return ir_build_atomic_load_gen(ira, &instruction->base.base, casted_ptr, ordering, operand_type); |
| 28490 | 28482 | } |
| 28491 | 28483 | |
| 28492 | 28484 | static IrInstGen *ir_analyze_instruction_atomic_store(IrAnalyze *ira, IrInstSrcAtomicStore *instruction) { |
| 28493 | | ZigType *actual_type; |
| 28494 | | ZigType *operand_type = ir_resolve_atomic_operand_type(ira, instruction->operand_type->child, &actual_type); |
| 28485 | ZigType *operand_type = ir_resolve_atomic_operand_type(ira, instruction->operand_type->child); |
| 28495 | 28486 | if (type_is_invalid(operand_type)) |
| 28496 | 28487 | return ira->codegen->invalid_inst_gen; |
| 28497 | 28488 | |
| ... | ... | @@ -28535,7 +28526,7 @@ static IrInstGen *ir_analyze_instruction_atomic_store(IrAnalyze *ira, IrInstSrcA |
| 28535 | 28526 | return result; |
| 28536 | 28527 | } |
| 28537 | 28528 | |
| 28538 | | return ir_build_atomic_store_gen(ira, &instruction->base.base, casted_ptr, casted_value, ordering, actual_type); |
| 28529 | return ir_build_atomic_store_gen(ira, &instruction->base.base, casted_ptr, casted_value, ordering); |
| 28539 | 28530 | } |
| 28540 | 28531 | |
| 28541 | 28532 | static IrInstGen *ir_analyze_instruction_save_err_ret_addr(IrAnalyze *ira, IrInstSrcSaveErrRetAddr *instruction) { |