| ... | ... | @@ -1304,7 +1304,7 @@ static Stage1ZirInst *ir_build_call_src(Stage1AstGen *ag, Scope *scope, AstNode |
| 1304 | 1304 | return &call_instruction->base; |
| 1305 | 1305 | } |
| 1306 | 1306 | |
| 1307 | | static Stage1ZirInst *ir_build_phi(Stage1AstGen *ag, Scope *scope, AstNode *source_node, |
| 1307 | static Stage1ZirInst *ir_build_phi(Stage1AstGen *ag, Scope *scope, AstNode *source_node, bool merge_comptime, |
| 1308 | 1308 | size_t incoming_count, Stage1ZirBasicBlock **incoming_blocks, Stage1ZirInst **incoming_values, |
| 1309 | 1309 | ResultLocPeerParent *peer_parent) |
| 1310 | 1310 | { |
| ... | ... | @@ -1316,6 +1316,7 @@ static Stage1ZirInst *ir_build_phi(Stage1AstGen *ag, Scope *scope, AstNode *sour |
| 1316 | 1316 | phi_instruction->incoming_blocks = incoming_blocks; |
| 1317 | 1317 | phi_instruction->incoming_values = incoming_values; |
| 1318 | 1318 | phi_instruction->peer_parent = peer_parent; |
| 1319 | phi_instruction->merge_comptime = merge_comptime; |
| 1319 | 1320 | |
| 1320 | 1321 | for (size_t i = 0; i < incoming_count; i += 1) { |
| 1321 | 1322 | ir_ref_bb(incoming_blocks[i]); |
| ... | ... | @@ -3393,7 +3394,7 @@ static Stage1ZirInst *astgen_block(Stage1AstGen *ag, Scope *parent_scope, AstNod |
| 3393 | 3394 | scope_block->peer_parent->peers.last()->next_bb = scope_block->end_block; |
| 3394 | 3395 | } |
| 3395 | 3396 | ir_set_cursor_at_end_and_append_block(ag, scope_block->end_block); |
| 3396 | | Stage1ZirInst *phi = ir_build_phi(ag, parent_scope, block_node, incoming_blocks.length, |
| 3397 | Stage1ZirInst *phi = ir_build_phi(ag, parent_scope, block_node, false, incoming_blocks.length, |
| 3397 | 3398 | incoming_blocks.items, incoming_values.items, scope_block->peer_parent); |
| 3398 | 3399 | return ir_expr_wrap(ag, parent_scope, phi, result_loc); |
| 3399 | 3400 | } else { |
| ... | ... | @@ -3423,7 +3424,7 @@ static Stage1ZirInst *astgen_block(Stage1AstGen *ag, Scope *parent_scope, AstNod |
| 3423 | 3424 | if (block_node->data.block.name != nullptr) { |
| 3424 | 3425 | ir_build_br(ag, parent_scope, block_node, scope_block->end_block, scope_block->is_comptime); |
| 3425 | 3426 | ir_set_cursor_at_end_and_append_block(ag, scope_block->end_block); |
| 3426 | | Stage1ZirInst *phi = ir_build_phi(ag, parent_scope, block_node, incoming_blocks.length, |
| 3427 | Stage1ZirInst *phi = ir_build_phi(ag, parent_scope, block_node, false, incoming_blocks.length, |
| 3427 | 3428 | incoming_blocks.items, incoming_values.items, scope_block->peer_parent); |
| 3428 | 3429 | result = ir_expr_wrap(ag, parent_scope, phi, result_loc); |
| 3429 | 3430 | } else { |
| ... | ... | @@ -3527,6 +3528,7 @@ static Stage1ZirInst *astgen_bool_or(Stage1AstGen *ag, Scope *scope, AstNode *no |
| 3527 | 3528 | // block for when val1 == true (don't even evaluate the second part) |
| 3528 | 3529 | Stage1ZirBasicBlock *true_block = ir_create_basic_block(ag, scope, "BoolOrTrue"); |
| 3529 | 3530 | |
| 3531 | Stage1ZirInst *val1_true = ir_build_const_bool(ag, scope, node, true); |
| 3530 | 3532 | ir_build_cond_br(ag, scope, node, val1, true_block, false_block, is_comptime); |
| 3531 | 3533 | |
| 3532 | 3534 | ir_set_cursor_at_end_and_append_block(ag, false_block); |
| ... | ... | @@ -3540,13 +3542,14 @@ static Stage1ZirInst *astgen_bool_or(Stage1AstGen *ag, Scope *scope, AstNode *no |
| 3540 | 3542 | ir_set_cursor_at_end_and_append_block(ag, true_block); |
| 3541 | 3543 | |
| 3542 | 3544 | Stage1ZirInst **incoming_values = heap::c_allocator.allocate<Stage1ZirInst *>(2); |
| 3543 | | incoming_values[0] = val1; |
| 3545 | incoming_values[0] = val1_true; |
| 3544 | 3546 | incoming_values[1] = val2; |
| 3545 | 3547 | Stage1ZirBasicBlock **incoming_blocks = heap::c_allocator.allocate<Stage1ZirBasicBlock *>(2); |
| 3546 | 3548 | incoming_blocks[0] = post_val1_block; |
| 3547 | 3549 | incoming_blocks[1] = post_val2_block; |
| 3548 | 3550 | |
| 3549 | | return ir_build_phi(ag, scope, node, 2, incoming_blocks, incoming_values, nullptr); |
| 3551 | const bool merge_comptime = true; |
| 3552 | return ir_build_phi(ag, scope, node, merge_comptime, 2, incoming_blocks, incoming_values, nullptr); |
| 3550 | 3553 | } |
| 3551 | 3554 | |
| 3552 | 3555 | static Stage1ZirInst *astgen_bool_and(Stage1AstGen *ag, Scope *scope, AstNode *node) { |
| ... | ... | @@ -3569,6 +3572,7 @@ static Stage1ZirInst *astgen_bool_and(Stage1AstGen *ag, Scope *scope, AstNode *n |
| 3569 | 3572 | // block for when val1 == false (don't even evaluate the second part) |
| 3570 | 3573 | Stage1ZirBasicBlock *false_block = ir_create_basic_block(ag, scope, "BoolAndFalse"); |
| 3571 | 3574 | |
| 3575 | Stage1ZirInst *val1_false = ir_build_const_bool(ag, scope, node, false); |
| 3572 | 3576 | ir_build_cond_br(ag, scope, node, val1, true_block, false_block, is_comptime); |
| 3573 | 3577 | |
| 3574 | 3578 | ir_set_cursor_at_end_and_append_block(ag, true_block); |
| ... | ... | @@ -3582,13 +3586,14 @@ static Stage1ZirInst *astgen_bool_and(Stage1AstGen *ag, Scope *scope, AstNode *n |
| 3582 | 3586 | ir_set_cursor_at_end_and_append_block(ag, false_block); |
| 3583 | 3587 | |
| 3584 | 3588 | Stage1ZirInst **incoming_values = heap::c_allocator.allocate<Stage1ZirInst *>(2); |
| 3585 | | incoming_values[0] = val1; |
| 3589 | incoming_values[0] = val1_false; |
| 3586 | 3590 | incoming_values[1] = val2; |
| 3587 | 3591 | Stage1ZirBasicBlock **incoming_blocks = heap::c_allocator.allocate<Stage1ZirBasicBlock *>(2); |
| 3588 | 3592 | incoming_blocks[0] = post_val1_block; |
| 3589 | 3593 | incoming_blocks[1] = post_val2_block; |
| 3590 | 3594 | |
| 3591 | | return ir_build_phi(ag, scope, node, 2, incoming_blocks, incoming_values, nullptr); |
| 3595 | const bool merge_comptime = true; |
| 3596 | return ir_build_phi(ag, scope, node, merge_comptime, 2, incoming_blocks, incoming_values, nullptr); |
| 3592 | 3597 | } |
| 3593 | 3598 | |
| 3594 | 3599 | static ResultLocPeerParent *ir_build_result_peers(Stage1AstGen *ag, Stage1ZirInst *cond_br_inst, |
| ... | ... | @@ -3678,7 +3683,7 @@ static Stage1ZirInst *astgen_orelse(Stage1AstGen *ag, Scope *parent_scope, AstNo |
| 3678 | 3683 | Stage1ZirBasicBlock **incoming_blocks = heap::c_allocator.allocate<Stage1ZirBasicBlock *>(2); |
| 3679 | 3684 | incoming_blocks[0] = after_null_block; |
| 3680 | 3685 | incoming_blocks[1] = after_ok_block; |
| 3681 | | Stage1ZirInst *phi = ir_build_phi(ag, parent_scope, node, 2, incoming_blocks, incoming_values, peer_parent); |
| 3686 | Stage1ZirInst *phi = ir_build_phi(ag, parent_scope, node, false, 2, incoming_blocks, incoming_values, peer_parent); |
| 3682 | 3687 | return ir_lval_wrap(ag, parent_scope, phi, lval, result_loc); |
| 3683 | 3688 | } |
| 3684 | 3689 | |
| ... | ... | @@ -5589,7 +5594,7 @@ static Stage1ZirInst *astgen_if_bool_expr(Stage1AstGen *ag, Scope *scope, AstNod |
| 5589 | 5594 | incoming_blocks[0] = after_then_block; |
| 5590 | 5595 | incoming_blocks[1] = after_else_block; |
| 5591 | 5596 | |
| 5592 | | Stage1ZirInst *phi = ir_build_phi(ag, scope, node, 2, incoming_blocks, incoming_values, peer_parent); |
| 5597 | Stage1ZirInst *phi = ir_build_phi(ag, scope, node, false, 2, incoming_blocks, incoming_values, peer_parent); |
| 5593 | 5598 | return ir_expr_wrap(ag, scope, phi, result_loc); |
| 5594 | 5599 | } |
| 5595 | 5600 | |
| ... | ... | @@ -6224,7 +6229,7 @@ static Stage1ZirInst *astgen_while_expr(Stage1AstGen *ag, Scope *scope, AstNode |
| 6224 | 6229 | peer_parent->peers.last()->next_bb = end_block; |
| 6225 | 6230 | } |
| 6226 | 6231 | |
| 6227 | | Stage1ZirInst *phi = ir_build_phi(ag, scope, node, incoming_blocks.length, |
| 6232 | Stage1ZirInst *phi = ir_build_phi(ag, scope, node, false, incoming_blocks.length, |
| 6228 | 6233 | incoming_blocks.items, incoming_values.items, peer_parent); |
| 6229 | 6234 | return ir_expr_wrap(ag, scope, phi, result_loc); |
| 6230 | 6235 | } else if (var_symbol != nullptr) { |
| ... | ... | @@ -6334,7 +6339,7 @@ static Stage1ZirInst *astgen_while_expr(Stage1AstGen *ag, Scope *scope, AstNode |
| 6334 | 6339 | peer_parent->peers.last()->next_bb = end_block; |
| 6335 | 6340 | } |
| 6336 | 6341 | |
| 6337 | | Stage1ZirInst *phi = ir_build_phi(ag, scope, node, incoming_blocks.length, |
| 6342 | Stage1ZirInst *phi = ir_build_phi(ag, scope, node, false, incoming_blocks.length, |
| 6338 | 6343 | incoming_blocks.items, incoming_values.items, peer_parent); |
| 6339 | 6344 | return ir_expr_wrap(ag, scope, phi, result_loc); |
| 6340 | 6345 | } else { |
| ... | ... | @@ -6430,7 +6435,7 @@ static Stage1ZirInst *astgen_while_expr(Stage1AstGen *ag, Scope *scope, AstNode |
| 6430 | 6435 | peer_parent->peers.last()->next_bb = end_block; |
| 6431 | 6436 | } |
| 6432 | 6437 | |
| 6433 | | Stage1ZirInst *phi = ir_build_phi(ag, scope, node, incoming_blocks.length, |
| 6438 | Stage1ZirInst *phi = ir_build_phi(ag, scope, node, false, incoming_blocks.length, |
| 6434 | 6439 | incoming_blocks.items, incoming_values.items, peer_parent); |
| 6435 | 6440 | return ir_expr_wrap(ag, scope, phi, result_loc); |
| 6436 | 6441 | } |
| ... | ... | @@ -6582,7 +6587,7 @@ static Stage1ZirInst *astgen_for_expr(Stage1AstGen *ag, Scope *parent_scope, Ast |
| 6582 | 6587 | peer_parent->peers.last()->next_bb = end_block; |
| 6583 | 6588 | } |
| 6584 | 6589 | |
| 6585 | | Stage1ZirInst *phi = ir_build_phi(ag, parent_scope, node, incoming_blocks.length, |
| 6590 | Stage1ZirInst *phi = ir_build_phi(ag, parent_scope, node, false, incoming_blocks.length, |
| 6586 | 6591 | incoming_blocks.items, incoming_values.items, peer_parent); |
| 6587 | 6592 | return ir_lval_wrap(ag, parent_scope, phi, lval, result_loc); |
| 6588 | 6593 | } |
| ... | ... | @@ -6910,7 +6915,7 @@ static Stage1ZirInst *astgen_if_optional_expr(Stage1AstGen *ag, Scope *scope, As |
| 6910 | 6915 | incoming_blocks[0] = after_then_block; |
| 6911 | 6916 | incoming_blocks[1] = after_else_block; |
| 6912 | 6917 | |
| 6913 | | Stage1ZirInst *phi = ir_build_phi(ag, scope, node, 2, incoming_blocks, incoming_values, peer_parent); |
| 6918 | Stage1ZirInst *phi = ir_build_phi(ag, scope, node, false, 2, incoming_blocks, incoming_values, peer_parent); |
| 6914 | 6919 | return ir_expr_wrap(ag, scope, phi, result_loc); |
| 6915 | 6920 | } |
| 6916 | 6921 | |
| ... | ... | @@ -7008,7 +7013,7 @@ static Stage1ZirInst *astgen_if_err_expr(Stage1AstGen *ag, Scope *scope, AstNode |
| 7008 | 7013 | incoming_blocks[0] = after_then_block; |
| 7009 | 7014 | incoming_blocks[1] = after_else_block; |
| 7010 | 7015 | |
| 7011 | | Stage1ZirInst *phi = ir_build_phi(ag, scope, node, 2, incoming_blocks, incoming_values, peer_parent); |
| 7016 | Stage1ZirInst *phi = ir_build_phi(ag, scope, node, false, 2, incoming_blocks, incoming_values, peer_parent); |
| 7012 | 7017 | return ir_expr_wrap(ag, scope, phi, result_loc); |
| 7013 | 7018 | } |
| 7014 | 7019 | |
| ... | ... | @@ -7344,7 +7349,7 @@ static Stage1ZirInst *astgen_switch_expr(Stage1AstGen *ag, Scope *scope, AstNode |
| 7344 | 7349 | if (incoming_blocks.length == 0) { |
| 7345 | 7350 | result_instruction = ir_build_const_void(ag, scope, node); |
| 7346 | 7351 | } else { |
| 7347 | | result_instruction = ir_build_phi(ag, scope, node, incoming_blocks.length, |
| 7352 | result_instruction = ir_build_phi(ag, scope, node, false, incoming_blocks.length, |
| 7348 | 7353 | incoming_blocks.items, incoming_values.items, peer_parent); |
| 7349 | 7354 | } |
| 7350 | 7355 | return ir_lval_wrap(ag, scope, result_instruction, lval, result_loc); |
| ... | ... | @@ -7671,7 +7676,7 @@ static Stage1ZirInst *astgen_catch(Stage1AstGen *ag, Scope *parent_scope, AstNod |
| 7671 | 7676 | Stage1ZirBasicBlock **incoming_blocks = heap::c_allocator.allocate<Stage1ZirBasicBlock *>(2); |
| 7672 | 7677 | incoming_blocks[0] = after_err_block; |
| 7673 | 7678 | incoming_blocks[1] = after_ok_block; |
| 7674 | | Stage1ZirInst *phi = ir_build_phi(ag, parent_scope, node, 2, incoming_blocks, incoming_values, peer_parent); |
| 7679 | Stage1ZirInst *phi = ir_build_phi(ag, parent_scope, node, false, 2, incoming_blocks, incoming_values, peer_parent); |
| 7675 | 7680 | return ir_lval_wrap(ag, parent_scope, phi, lval, result_loc); |
| 7676 | 7681 | } |
| 7677 | 7682 | |