(builder: IRBuilder, expr: OpExpr)
| 709 | |
| 710 | |
| 711 | def transform_op_expr(builder: IRBuilder, expr: OpExpr) -> Value: |
| 712 | if expr.op in ("and", "or"): |
| 713 | return builder.shortcircuit_expr(expr) |
| 714 | |
| 715 | # Special case for string formatting |
| 716 | if expr.op == "%" and isinstance(expr.left, (StrExpr, BytesExpr)): |
| 717 | ret = translate_printf_style_formatting(builder, expr.left, expr.right) |
| 718 | if ret is not None: |
| 719 | return ret |
| 720 | |
| 721 | folded = try_constant_fold(builder, expr) |
| 722 | if folded: |
| 723 | return folded |
| 724 | |
| 725 | borrow_left = False |
| 726 | borrow_right = False |
| 727 | |
| 728 | ltype = builder.node_type(expr.left) |
| 729 | rtype = builder.node_type(expr.right) |
| 730 | |
| 731 | # Special case some int ops to allow borrowing operands. |
| 732 | if is_int_rprimitive(ltype) and is_int_rprimitive(rtype): |
| 733 | if expr.op == "//": |
| 734 | expr = try_optimize_int_floor_divide(builder, expr) |
| 735 | if expr.op in int_borrow_friendly_op: |
| 736 | borrow_left = is_borrow_friendly_expr(builder, expr.right) |
| 737 | borrow_right = True |
| 738 | elif is_fixed_width_rtype(ltype) and is_fixed_width_rtype(rtype): |
| 739 | borrow_left = is_borrow_friendly_expr(builder, expr.right) |
| 740 | borrow_right = True |
| 741 | |
| 742 | left = builder.accept(expr.left, can_borrow=borrow_left) |
| 743 | right = builder.accept(expr.right, can_borrow=borrow_right) |
| 744 | return builder.binary_op(left, right, expr.op, expr.line) |
| 745 | |
| 746 | |
| 747 | def try_optimize_int_floor_divide(builder: IRBuilder, expr: OpExpr) -> OpExpr: |
no test coverage detected
searching dependent graphs…