Skip to content

Utils

utils

const_evaluate_operand_attribute(operand: SSAValue) -> IntegerAttr | None

Try to constant evaluate an SSA value, returning None on failure.

Source code in xdsl/transforms/canonicalization_patterns/utils.py
 6
 7
 8
 9
10
11
12
13
def const_evaluate_operand_attribute(operand: SSAValue) -> IntegerAttr | None:
    """
    Try to constant evaluate an SSA value, returning None on failure.
    """
    if isinstance(op := operand.owner, arith.ConstantOp) and isinstance(
        val := op.value, IntegerAttr
    ):
        return val

const_evaluate_operand(operand: SSAValue) -> int | None

Try to constant evaluate an SSA value, returning None on failure.

Source code in xdsl/transforms/canonicalization_patterns/utils.py
16
17
18
19
20
21
def const_evaluate_operand(operand: SSAValue) -> int | None:
    """
    Try to constant evaluate an SSA value, returning None on failure.
    """
    if (attr := const_evaluate_operand_attribute(operand)) is not None:
        return attr.value.data