Skip to content

Polynomial

polynomial

A polynomial dialect for representing unevaluated polynomial approximations, designed for use with equality saturation.

Cost estimation can be done on a single polynomial.eval op that carries all the information needed. After extraction, the selected polynomial variant will be expanded into arithmetic operations.

HEIR Documentation

Polynomial = Dialect('polynomial', [], [RingAttr, PolynomialType]) module-attribute

RingAttr dataclass

Bases: ParametrizedAttribute

A polynomial ring, parameterized by the coefficient type.

Syntax: #polynomial.ring

Source code in xdsl/dialects/polynomial.py
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
@irdl_attr_definition
class RingAttr(ParametrizedAttribute):
    """
    A polynomial ring, parameterized by the coefficient type.

    Syntax: #polynomial.ring<coefficientType=f64>
    """

    name = "polynomial.ring"

    coefficient_type: Attribute

    @classmethod
    def parse_parameters(cls, parser: AttrParser) -> Sequence[Attribute]:
        with parser.in_angle_brackets():
            parser.parse_keyword("coefficientType")
            parser.parse_punctuation("=")
            coeff_type = parser.parse_type()
        return (coeff_type,)

    def print_parameters(self, printer: Printer) -> None:
        printer.print_string("<coefficientType = ")
        printer.print_attribute(self.coefficient_type)
        printer.print_string(">")

name = 'polynomial.ring' class-attribute instance-attribute

coefficient_type: Attribute instance-attribute

parse_parameters(parser: AttrParser) -> Sequence[Attribute] classmethod

Source code in xdsl/dialects/polynomial.py
42
43
44
45
46
47
48
@classmethod
def parse_parameters(cls, parser: AttrParser) -> Sequence[Attribute]:
    with parser.in_angle_brackets():
        parser.parse_keyword("coefficientType")
        parser.parse_punctuation("=")
        coeff_type = parser.parse_type()
    return (coeff_type,)

print_parameters(printer: Printer) -> None

Source code in xdsl/dialects/polynomial.py
50
51
52
53
def print_parameters(self, printer: Printer) -> None:
    printer.print_string("<coefficientType = ")
    printer.print_attribute(self.coefficient_type)
    printer.print_string(">")

PolynomialType dataclass

Bases: ParametrizedAttribute, TypeAttribute

Type of an element of a polynomial ring.

Syntax: !polynomial.polynomial>

Source code in xdsl/dialects/polynomial.py
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
@irdl_attr_definition
class PolynomialType(ParametrizedAttribute, TypeAttribute):
    """
    Type of an element of a polynomial ring.

    Syntax: !polynomial.polynomial<ring=<coefficientType=f64>>
    """

    name = "polynomial.polynomial"

    ring: RingAttr

    @classmethod
    def parse_parameters(cls, parser: AttrParser) -> Sequence[Attribute]:
        with parser.in_angle_brackets():
            parser.parse_keyword("ring")
            parser.parse_punctuation("=")
            # Accept either inline form `<coefficientType=...>` or
            # attribute reference like `#alias` / `#polynomial.ring<...>`.
            # HEIR's printer often hoists ring attributes into top-level
            # aliases, so both need to be handled on round-trip.
            ring = parser.parse_optional_attribute()
            if ring is None:
                ring_params = RingAttr.parse_parameters(parser)
                ring = RingAttr.new(ring_params)
            elif not isinstance(ring, RingAttr):
                parser.raise_error(f"expected RingAttr in polynomial type, got {ring}")
        return (ring,)

    def print_parameters(self, printer: Printer) -> None:
        printer.print_string("<ring = ")
        self.ring.print_parameters(printer)
        printer.print_string(">")

name = 'polynomial.polynomial' class-attribute instance-attribute

ring: RingAttr instance-attribute

parse_parameters(parser: AttrParser) -> Sequence[Attribute] classmethod

Source code in xdsl/dialects/polynomial.py
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
@classmethod
def parse_parameters(cls, parser: AttrParser) -> Sequence[Attribute]:
    with parser.in_angle_brackets():
        parser.parse_keyword("ring")
        parser.parse_punctuation("=")
        # Accept either inline form `<coefficientType=...>` or
        # attribute reference like `#alias` / `#polynomial.ring<...>`.
        # HEIR's printer often hoists ring attributes into top-level
        # aliases, so both need to be handled on round-trip.
        ring = parser.parse_optional_attribute()
        if ring is None:
            ring_params = RingAttr.parse_parameters(parser)
            ring = RingAttr.new(ring_params)
        elif not isinstance(ring, RingAttr):
            parser.raise_error(f"expected RingAttr in polynomial type, got {ring}")
    return (ring,)

print_parameters(printer: Printer) -> None

Source code in xdsl/dialects/polynomial.py
85
86
87
88
def print_parameters(self, printer: Printer) -> None:
    printer.print_string("<ring = ")
    self.ring.print_parameters(printer)
    printer.print_string(">")