Skip to content

Predicate

predicate

This file implements some of the core data structures used in the pdl-to-pdl-interp conversion.

POSITION_COSTS = {OperationPosition: 1, OperandPosition: 2, OperandGroupPosition: 3, AttributePosition: 4, ConstraintPosition: 5, ResultPosition: 6, ResultGroupPosition: 7, TypePosition: 8, AttributeLiteralPosition: 9, TypeLiteralPosition: 10, UsersPosition: 11, ForEachPosition: 12} module-attribute

Different position types are ranked by priority. A lower cost means a higher priority. This is used to decide which position to branch on first when evaluating predicates.

QUESTION_COSTS = {IsNotNullQuestion: 1, OperationNameQuestion: 2, OperandCountAtLeastQuestion: 3, OperandCountQuestion: 4, ResultCountAtLeastQuestion: 5, ResultCountQuestion: 6, EqualToQuestion: 7, AttributeConstraintQuestion: 8, TypeConstraintQuestion: 9, ConstraintQuestion: 10} module-attribute

Different question types are ranked by priority. A lower cost means a higher priority. This is used to decide which question to branch on first when evaluating predicates.

Position dataclass

Bases: ABC

The position class encodes a location in a pattern. Each pattern has a root position. From there, other positions can be reached representing operands, results, and more.

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
@dataclass(frozen=True)
class Position(ABC):
    """
    The position class encodes a location in a pattern.
    Each pattern has a root position. From there, other positions can be reached representing operands, results, and more.
    """

    parent: Optional["Position"] = None

    def get_operation_depth(self) -> int:
        """Returns depth of first ancestor operation position"""
        op = self.get_base_operation()
        if op is None:
            return 0
        return op.depth

    def get_base_operation(self) -> "OperationPosition|None":
        pos = self
        while not isinstance(pos, OperationPosition):
            if pos.parent is None:
                return None
            pos = pos.parent
        return pos

parent: Optional[Position] = None class-attribute instance-attribute

__init__(parent: Optional[Position] = None) -> None

get_operation_depth() -> int

Returns depth of first ancestor operation position

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
def get_operation_depth(self) -> int:
    """Returns depth of first ancestor operation position"""
    op = self.get_base_operation()
    if op is None:
        return 0
    return op.depth

get_base_operation() -> OperationPosition | None

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
def get_base_operation(self) -> "OperationPosition|None":
    pos = self
    while not isinstance(pos, OperationPosition):
        if pos.parent is None:
            return None
        pos = pos.parent
    return pos

OperationPosition dataclass

Bases: Position

Represents an operation in the IR

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
@dataclass(frozen=True, kw_only=True)
class OperationPosition(Position):
    """Represents an operation in the IR"""

    depth: int

    def is_root(self) -> bool:
        return self.depth == 0

    def is_operand_defining_op(self) -> bool:
        return isinstance(self.parent, OperandPosition | OperandGroupPosition)

    def __repr__(self):
        if self.is_root():
            return "root"
        else:
            return self.parent.__repr__() + ".defining_op"

    def get_operand(self, operand_num: int) -> "OperandPosition":
        return OperandPosition(operand_number=operand_num, parent=self)

    def get_operand_group(
        self, group_num: int, is_variadic: bool
    ) -> "OperandGroupPosition":
        return OperandGroupPosition(
            group_number=group_num, is_variadic=is_variadic, parent=self
        )

    def get_all_operands(self) -> "OperandGroupPosition":
        return OperandGroupPosition(group_number=None, is_variadic=True, parent=self)

    def get_result(self, result_num: int) -> "ResultPosition":
        return ResultPosition(result_number=result_num, parent=self)

    def get_result_group(
        self, group_num: int | None, is_variadic: bool
    ) -> "ResultGroupPosition":
        return ResultGroupPosition(
            group_number=group_num, is_variadic=is_variadic, parent=self
        )

    def get_all_results(self) -> "ResultGroupPosition":
        return ResultGroupPosition(group_number=None, is_variadic=True, parent=self)

    def get_attribute(self, attr_name: str) -> "AttributePosition":
        return AttributePosition(attribute_name=attr_name, parent=self)

    def get_attribute_literal(self, value: Attribute) -> "AttributeLiteralPosition":
        return AttributeLiteralPosition(value=value, parent=None)

depth: int instance-attribute

__init__(parent: Optional[Position] = None, *, depth: int) -> None

is_root() -> bool

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
def is_root(self) -> bool:
    return self.depth == 0

is_operand_defining_op() -> bool

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
def is_operand_defining_op(self) -> bool:
    return isinstance(self.parent, OperandPosition | OperandGroupPosition)

__repr__()

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
def __repr__(self):
    if self.is_root():
        return "root"
    else:
        return self.parent.__repr__() + ".defining_op"

get_operand(operand_num: int) -> OperandPosition

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
def get_operand(self, operand_num: int) -> "OperandPosition":
    return OperandPosition(operand_number=operand_num, parent=self)

get_operand_group(group_num: int, is_variadic: bool) -> OperandGroupPosition

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
def get_operand_group(
    self, group_num: int, is_variadic: bool
) -> "OperandGroupPosition":
    return OperandGroupPosition(
        group_number=group_num, is_variadic=is_variadic, parent=self
    )

get_all_operands() -> OperandGroupPosition

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
def get_all_operands(self) -> "OperandGroupPosition":
    return OperandGroupPosition(group_number=None, is_variadic=True, parent=self)

get_result(result_num: int) -> ResultPosition

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
def get_result(self, result_num: int) -> "ResultPosition":
    return ResultPosition(result_number=result_num, parent=self)

get_result_group(group_num: int | None, is_variadic: bool) -> ResultGroupPosition

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
def get_result_group(
    self, group_num: int | None, is_variadic: bool
) -> "ResultGroupPosition":
    return ResultGroupPosition(
        group_number=group_num, is_variadic=is_variadic, parent=self
    )

get_all_results() -> ResultGroupPosition

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
def get_all_results(self) -> "ResultGroupPosition":
    return ResultGroupPosition(group_number=None, is_variadic=True, parent=self)

get_attribute(attr_name: str) -> AttributePosition

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
def get_attribute(self, attr_name: str) -> "AttributePosition":
    return AttributePosition(attribute_name=attr_name, parent=self)

get_attribute_literal(value: Attribute) -> AttributeLiteralPosition

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
def get_attribute_literal(self, value: Attribute) -> "AttributeLiteralPosition":
    return AttributeLiteralPosition(value=value, parent=None)

ValuePosition dataclass

Bases: Position

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
class ValuePosition(Position):
    def get_defining_op(self) -> OperationPosition:
        return OperationPosition(depth=self.get_operation_depth() + 1, parent=self)

    def get_type(self) -> "TypePosition":
        return TypePosition(parent=self)

    def get_type_literal(self, value: Attribute) -> "TypeLiteralPosition":
        return TypeLiteralPosition(value=value, parent=None)

    def get_users(self, use_representative: bool) -> "UsersPosition":
        return UsersPosition(parent=self, use_representative=use_representative)

get_defining_op() -> OperationPosition

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
def get_defining_op(self) -> OperationPosition:
    return OperationPosition(depth=self.get_operation_depth() + 1, parent=self)

get_type() -> TypePosition

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
def get_type(self) -> "TypePosition":
    return TypePosition(parent=self)

get_type_literal(value: Attribute) -> TypeLiteralPosition

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
def get_type_literal(self, value: Attribute) -> "TypeLiteralPosition":
    return TypeLiteralPosition(value=value, parent=None)

get_users(use_representative: bool) -> UsersPosition

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
def get_users(self, use_representative: bool) -> "UsersPosition":
    return UsersPosition(parent=self, use_representative=use_representative)

OperandPosition dataclass

Bases: ValuePosition

Represents an operand of an operation

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
@dataclass(frozen=True, kw_only=True)
class OperandPosition(ValuePosition):
    """Represents an operand of an operation"""

    operand_number: int

    def __repr__(self):
        return f"{self.parent.__repr__()}.operand[{self.operand_number}]"

operand_number: int instance-attribute

__init__(parent: Optional[Position] = None, *, operand_number: int) -> None

__repr__()

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
def __repr__(self):
    return f"{self.parent.__repr__()}.operand[{self.operand_number}]"

OperandGroupPosition dataclass

Bases: Position

Represents a group of operands

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
@dataclass(frozen=True, kw_only=True)
class OperandGroupPosition(Position):
    """Represents a group of operands"""

    group_number: int | None
    is_variadic: bool

    def get_defining_op(self) -> "OperationPosition":
        return OperationPosition(depth=self.get_operation_depth() + 1, parent=self)

    def get_type(self) -> "TypePosition":
        return TypePosition(parent=self)

group_number: int | None instance-attribute

is_variadic: bool instance-attribute

__init__(parent: Optional[Position] = None, *, group_number: int | None, is_variadic: bool) -> None

get_defining_op() -> OperationPosition

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
def get_defining_op(self) -> "OperationPosition":
    return OperationPosition(depth=self.get_operation_depth() + 1, parent=self)

get_type() -> TypePosition

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
def get_type(self) -> "TypePosition":
    return TypePosition(parent=self)

ResultPosition dataclass

Bases: ValuePosition

Represents a result of an operation

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
@dataclass(frozen=True, kw_only=True)
class ResultPosition(ValuePosition):
    """Represents a result of an operation"""

    result_number: int

    def __repr__(self):
        return f"{self.parent.__repr__()}.result[{self.result_number}]"

result_number: int instance-attribute

__init__(parent: Optional[Position] = None, *, result_number: int) -> None

__repr__()

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
def __repr__(self):
    return f"{self.parent.__repr__()}.result[{self.result_number}]"

AttributePosition dataclass

Bases: Position

Represents an attribute of an operation

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
@dataclass(frozen=True, kw_only=True)
class AttributePosition(Position):
    """Represents an attribute of an operation"""

    attribute_name: str

    def __repr__(self):
        return f"{self.parent.__repr__()}.attribute[{self.attribute_name}]"

    def get_type(self) -> "TypePosition":
        return TypePosition(parent=self)

attribute_name: str instance-attribute

__init__(parent: Optional[Position] = None, *, attribute_name: str) -> None

__repr__()

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
def __repr__(self):
    return f"{self.parent.__repr__()}.attribute[{self.attribute_name}]"

get_type() -> TypePosition

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
def get_type(self) -> "TypePosition":
    return TypePosition(parent=self)

TypePosition dataclass

Bases: Position

Represents the type of a value

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
@dataclass(frozen=True)
class TypePosition(Position):
    """Represents the type of a value"""

    def __repr__(self):
        return f"{self.parent.__repr__()}.type"

    def get_type_literal(self, value: Attribute) -> "TypeLiteralPosition":
        return TypeLiteralPosition(value=value, parent=None)

__init__(parent: Optional[Position] = None) -> None

__repr__()

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
def __repr__(self):
    return f"{self.parent.__repr__()}.type"

get_type_literal(value: Attribute) -> TypeLiteralPosition

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
def get_type_literal(self, value: Attribute) -> "TypeLiteralPosition":
    return TypeLiteralPosition(value=value, parent=None)

UsersPosition dataclass

Bases: Position

Represents users of a value

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
@dataclass(frozen=True, kw_only=True)
class UsersPosition(Position):
    """Represents users of a value"""

    use_representative: bool

    def get_for_each(self, for_each_id: int) -> "ForEachPosition":
        return ForEachPosition(parent=self, id=for_each_id)

use_representative: bool instance-attribute

__init__(parent: Optional[Position] = None, *, use_representative: bool) -> None

get_for_each(for_each_id: int) -> ForEachPosition

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
def get_for_each(self, for_each_id: int) -> "ForEachPosition":
    return ForEachPosition(parent=self, id=for_each_id)

ForEachPosition dataclass

Bases: Position

Represents an iterative choice of an operation from a set of users.

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
@dataclass(frozen=True, kw_only=True)
class ForEachPosition(Position):
    """Represents an iterative choice of an operation from a set of users."""

    id: int

    def get_passthrough_op(self) -> "OperationPosition":
        return OperationPosition(depth=self.get_operation_depth() + 1, parent=self)

id: int instance-attribute

__init__(parent: Optional[Position] = None, *, id: int) -> None

get_passthrough_op() -> OperationPosition

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
def get_passthrough_op(self) -> "OperationPosition":
    return OperationPosition(depth=self.get_operation_depth() + 1, parent=self)

ResultGroupPosition dataclass

Bases: Position

Represents a group of results

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
@dataclass(frozen=True, kw_only=True)
class ResultGroupPosition(Position):
    """Represents a group of results"""

    group_number: int | None
    is_variadic: bool

    def get_type(self) -> "TypePosition":
        return TypePosition(parent=self)

group_number: int | None instance-attribute

is_variadic: bool instance-attribute

__init__(parent: Optional[Position] = None, *, group_number: int | None, is_variadic: bool) -> None

get_type() -> TypePosition

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
def get_type(self) -> "TypePosition":
    return TypePosition(parent=self)

AttributeLiteralPosition dataclass

Bases: Position

Represents a literal attribute value

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
@dataclass(frozen=True, kw_only=True)
class AttributeLiteralPosition(Position):
    """Represents a literal attribute value"""

    value: Attribute

value: Attribute instance-attribute

__init__(parent: Optional[Position] = None, *, value: Attribute) -> None

TypeLiteralPosition dataclass

Bases: Position

Represents a literal type value

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
@dataclass(frozen=True, kw_only=True)
class TypeLiteralPosition(Position):
    """Represents a literal type value"""

    value: Attribute  # Can be a single type or array of types

    @staticmethod
    def get_type_literal(value: Attribute) -> "TypeLiteralPosition":
        return TypeLiteralPosition(value=value, parent=None)

value: Attribute instance-attribute

__init__(parent: Optional[Position] = None, *, value: Attribute) -> None

get_type_literal(value: Attribute) -> TypeLiteralPosition staticmethod

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
@staticmethod
def get_type_literal(value: Attribute) -> "TypeLiteralPosition":
    return TypeLiteralPosition(value=value, parent=None)

ConstraintPosition dataclass

Bases: Position

Represents a result from a constraint

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
@dataclass(frozen=True, kw_only=True)
class ConstraintPosition(Position):
    """Represents a result from a constraint"""

    constraint: "ConstraintQuestion"
    result_index: int

    @staticmethod
    def get_constraint(
        constraint_question: "ConstraintQuestion", result_index: int
    ) -> "ConstraintPosition":
        return ConstraintPosition(
            constraint=constraint_question, result_index=result_index, parent=None
        )

constraint: ConstraintQuestion instance-attribute

result_index: int instance-attribute

__init__(parent: Optional[Position] = None, *, constraint: ConstraintQuestion, result_index: int) -> None

get_constraint(constraint_question: ConstraintQuestion, result_index: int) -> ConstraintPosition staticmethod

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
@staticmethod
def get_constraint(
    constraint_question: "ConstraintQuestion", result_index: int
) -> "ConstraintPosition":
    return ConstraintPosition(
        constraint=constraint_question, result_index=result_index, parent=None
    )

Question dataclass

Represents a question/check to perform

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
@dataclass(frozen=True)
class Question:
    """Represents a question/check to perform"""

    pass

__init__() -> None

Answer dataclass

Represents an expected answer to a question

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
@dataclass(frozen=True)
class Answer:
    """Represents an expected answer to a question"""

    pass

__init__() -> None

Predicate dataclass

Base predicate class

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
@dataclass()
class Predicate:
    """Base predicate class"""

    q: Question
    a: Answer

    @staticmethod
    def get_is_not_null() -> "Predicate":
        return Predicate(IsNotNullQuestion(), TrueAnswer())

    @staticmethod
    def get_operation_name(name: str) -> "Predicate":
        return Predicate(OperationNameQuestion(), StringAnswer(value=name))

    @staticmethod
    def get_operand_count(count: int) -> "Predicate":
        return Predicate(OperandCountQuestion(), UnsignedAnswer(value=count))

    @staticmethod
    def get_result_count(count: int) -> "Predicate":
        return Predicate(ResultCountQuestion(), UnsignedAnswer(value=count))

    @staticmethod
    def get_equal_to(other_position: Position) -> "Predicate":
        return Predicate(EqualToQuestion(other_position=other_position), TrueAnswer())

    @staticmethod
    def get_operand_count_at_least(count: int) -> "Predicate":
        """Get predicate for minimum operand count (variadic case)"""
        return Predicate(OperandCountAtLeastQuestion(), UnsignedAnswer(value=count))

    @staticmethod
    def get_result_count_at_least(count: int) -> "Predicate":
        """Get predicate for minimum result count (variadic case)"""
        return Predicate(ResultCountAtLeastQuestion(), UnsignedAnswer(value=count))

    @staticmethod
    def get_attribute_constraint(attr_value: Attribute) -> "Predicate":
        """Get predicate for attribute value constraint"""
        return Predicate(
            AttributeConstraintQuestion(), AttributeAnswer(value=attr_value)
        )

    @staticmethod
    def get_type_constraint(
        type_value: TypeAttribute | ArrayAttr[TypeAttribute],
    ) -> "Predicate":
        """Get predicate for type value constraint"""
        return Predicate(TypeConstraintQuestion(), TypeAnswer(value=type_value))

    @staticmethod
    def get_constraint(
        name: str,
        arg_positions: tuple[Position, ...],
        result_types: tuple[pdl.AnyPDLType | pdl.RangeType[pdl.AnyPDLType], ...],
        is_negated: bool = False,
    ) -> "Predicate":
        """Get predicate for a native constraint"""
        question = ConstraintQuestion(
            name=name,
            arg_positions=tuple(arg_positions),
            result_types=tuple(result_types),
            is_negated=is_negated,
        )
        return Predicate(question, TrueAnswer())

q: Question instance-attribute

a: Answer instance-attribute

__init__(q: Question, a: Answer) -> None

get_is_not_null() -> Predicate staticmethod

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
@staticmethod
def get_is_not_null() -> "Predicate":
    return Predicate(IsNotNullQuestion(), TrueAnswer())

get_operation_name(name: str) -> Predicate staticmethod

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
@staticmethod
def get_operation_name(name: str) -> "Predicate":
    return Predicate(OperationNameQuestion(), StringAnswer(value=name))

get_operand_count(count: int) -> Predicate staticmethod

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
@staticmethod
def get_operand_count(count: int) -> "Predicate":
    return Predicate(OperandCountQuestion(), UnsignedAnswer(value=count))

get_result_count(count: int) -> Predicate staticmethod

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
@staticmethod
def get_result_count(count: int) -> "Predicate":
    return Predicate(ResultCountQuestion(), UnsignedAnswer(value=count))

get_equal_to(other_position: Position) -> Predicate staticmethod

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
@staticmethod
def get_equal_to(other_position: Position) -> "Predicate":
    return Predicate(EqualToQuestion(other_position=other_position), TrueAnswer())

get_operand_count_at_least(count: int) -> Predicate staticmethod

Get predicate for minimum operand count (variadic case)

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
@staticmethod
def get_operand_count_at_least(count: int) -> "Predicate":
    """Get predicate for minimum operand count (variadic case)"""
    return Predicate(OperandCountAtLeastQuestion(), UnsignedAnswer(value=count))

get_result_count_at_least(count: int) -> Predicate staticmethod

Get predicate for minimum result count (variadic case)

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
@staticmethod
def get_result_count_at_least(count: int) -> "Predicate":
    """Get predicate for minimum result count (variadic case)"""
    return Predicate(ResultCountAtLeastQuestion(), UnsignedAnswer(value=count))

get_attribute_constraint(attr_value: Attribute) -> Predicate staticmethod

Get predicate for attribute value constraint

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
@staticmethod
def get_attribute_constraint(attr_value: Attribute) -> "Predicate":
    """Get predicate for attribute value constraint"""
    return Predicate(
        AttributeConstraintQuestion(), AttributeAnswer(value=attr_value)
    )

get_type_constraint(type_value: TypeAttribute | ArrayAttr[TypeAttribute]) -> Predicate staticmethod

Get predicate for type value constraint

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
@staticmethod
def get_type_constraint(
    type_value: TypeAttribute | ArrayAttr[TypeAttribute],
) -> "Predicate":
    """Get predicate for type value constraint"""
    return Predicate(TypeConstraintQuestion(), TypeAnswer(value=type_value))

get_constraint(name: str, arg_positions: tuple[Position, ...], result_types: tuple[pdl.AnyPDLType | pdl.RangeType[pdl.AnyPDLType], ...], is_negated: bool = False) -> Predicate staticmethod

Get predicate for a native constraint

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
@staticmethod
def get_constraint(
    name: str,
    arg_positions: tuple[Position, ...],
    result_types: tuple[pdl.AnyPDLType | pdl.RangeType[pdl.AnyPDLType], ...],
    is_negated: bool = False,
) -> "Predicate":
    """Get predicate for a native constraint"""
    question = ConstraintQuestion(
        name=name,
        arg_positions=tuple(arg_positions),
        result_types=tuple(result_types),
        is_negated=is_negated,
    )
    return Predicate(question, TrueAnswer())

IsNotNullQuestion dataclass

Bases: Question

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
@dataclass(frozen=True)
class IsNotNullQuestion(Question):
    pass

__init__() -> None

OperationNameQuestion dataclass

Bases: Question

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
@dataclass(frozen=True)
class OperationNameQuestion(Question):
    pass

__init__() -> None

OperandCountQuestion dataclass

Bases: Question

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
@dataclass(frozen=True)
class OperandCountQuestion(Question):
    pass

__init__() -> None

ResultCountQuestion dataclass

Bases: Question

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
@dataclass(frozen=True)
class ResultCountQuestion(Question):
    pass

__init__() -> None

EqualToQuestion dataclass

Bases: Question

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
@dataclass(frozen=True)
class EqualToQuestion(Question):
    other_position: Position

other_position: Position instance-attribute

__init__(other_position: Position) -> None

OperandCountAtLeastQuestion dataclass

Bases: Question

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
@dataclass(frozen=True)
class OperandCountAtLeastQuestion(Question):
    pass

__init__() -> None

ResultCountAtLeastQuestion dataclass

Bases: Question

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
@dataclass(frozen=True)
class ResultCountAtLeastQuestion(Question):
    pass

__init__() -> None

AttributeConstraintQuestion dataclass

Bases: Question

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
@dataclass(frozen=True)
class AttributeConstraintQuestion(Question):
    pass

__init__() -> None

TypeConstraintQuestion dataclass

Bases: Question

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
@dataclass(frozen=True)
class TypeConstraintQuestion(Question):
    pass

__init__() -> None

ConstraintQuestion dataclass

Bases: Question

Represents a native constraint check

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
@dataclass(frozen=True)
class ConstraintQuestion(Question):
    """Represents a native constraint check"""

    name: str
    arg_positions: tuple[Position, ...]
    result_types: tuple[pdl.AnyPDLType | pdl.RangeType[pdl.AnyPDLType], ...]
    is_negated: bool

name: str instance-attribute

arg_positions: tuple[Position, ...] instance-attribute

result_types: tuple[pdl.AnyPDLType | pdl.RangeType[pdl.AnyPDLType], ...] instance-attribute

is_negated: bool instance-attribute

__init__(name: str, arg_positions: tuple[Position, ...], result_types: tuple[pdl.AnyPDLType | pdl.RangeType[pdl.AnyPDLType], ...], is_negated: bool) -> None

TrueAnswer dataclass

Bases: Answer

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
@dataclass(frozen=True)
class TrueAnswer(Answer):
    pass

__init__() -> None

FalseAnswer dataclass

Bases: Answer

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
@dataclass(frozen=True)
class FalseAnswer(Answer):
    pass

__init__() -> None

UnsignedAnswer dataclass

Bases: Answer

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
@dataclass(frozen=True)
class UnsignedAnswer(Answer):
    value: int

value: int instance-attribute

__init__(value: int) -> None

StringAnswer dataclass

Bases: Answer

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
@dataclass(frozen=True)
class StringAnswer(Answer):
    value: str

value: str instance-attribute

__init__(value: str) -> None

AttributeAnswer dataclass

Bases: Answer

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
@dataclass(frozen=True)
class AttributeAnswer(Answer):
    value: Attribute

value: Attribute instance-attribute

__init__(value: Attribute) -> None

TypeAnswer dataclass

Bases: Answer

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
@dataclass(frozen=True)
class TypeAnswer(Answer):
    value: TypeAttribute | ArrayAttr[TypeAttribute]

value: TypeAttribute | ArrayAttr[TypeAttribute] instance-attribute

__init__(value: TypeAttribute | ArrayAttr[TypeAttribute]) -> None

PositionalPredicate dataclass

Bases: Predicate

A predicate applied to a specific position

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
@dataclass
class PositionalPredicate(Predicate):
    """A predicate applied to a specific position"""

    position: Position

position: Position instance-attribute

__init__(q: Question, a: Answer, position: Position) -> None

get_position_cost(position: Position) -> int

Get cost for a position type, with fallback for unknown types.

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
def get_position_cost(position: Position) -> int:
    """Get cost for a position type, with fallback for unknown types."""
    t = type(position)
    assert t in POSITION_COSTS
    return POSITION_COSTS[t]

get_question_cost(question: Question) -> int

Get cost for a question type, with fallback for unknown types.

Source code in xdsl/transforms/convert_pdl_to_pdl_interp/predicate.py
def get_question_cost(question: Question) -> int:
    """Get cost for a question type, with fallback for unknown types."""
    t = type(question)
    assert t in QUESTION_COSTS
    return QUESTION_COSTS[t]