@@ -13,157 +13,8 @@ include "mlir/IR/BuiltinAttributes.td"
1313include "mlir/IR/OpBase.td"
1414include "mlir/Interfaces/InferTypeOpInterface.td"
1515include "mlir/Interfaces/SideEffectInterfaces.td"
16-
17- def Polynomial_Dialect : Dialect {
18- let name = "polynomial";
19- let cppNamespace = "::mlir::polynomial";
20- let description = [{
21- The Polynomial dialect defines single-variable polynomial types and
22- operations.
23-
24- The simplest use of `polynomial` is to represent mathematical operations in
25- a polynomial ring `R[x]`, where `R` is another MLIR type like `i32`.
26-
27- More generally, this dialect supports representing polynomial operations in a
28- quotient ring `R[X]/(f(x))` for some statically fixed polynomial `f(x)`.
29- Two polyomials `p(x), q(x)` are considered equal in this ring if they have the
30- same remainder when dividing by `f(x)`. When a modulus is given, ring operations
31- are performed with reductions modulo `f(x)` and relative to the coefficient ring
32- `R`.
33-
34- Examples:
35-
36- ```mlir
37- // A constant polynomial in a ring with i32 coefficients and no polynomial modulus
38- #ring = #polynomial.ring<coefficientType=i32>
39- %a = polynomial.constant <1 + x**2 - 3x**3> : polynomial.polynomial<#ring>
40-
41- // A constant polynomial in a ring with i32 coefficients, modulo (x^1024 + 1)
42- #modulus = #polynomial.int_polynomial<1 + x**1024>
43- #ring = #polynomial.ring<coefficientType=i32, polynomialModulus=#modulus>
44- %a = polynomial.constant <1 + x**2 - 3x**3> : polynomial.polynomial<#ring>
45-
46- // A constant polynomial in a ring with i32 coefficients, with a polynomial
47- // modulus of (x^1024 + 1) and a coefficient modulus of 17.
48- #modulus = #polynomial.int_polynomial<1 + x**1024>
49- #ring = #polynomial.ring<coefficientType=i32, coefficientModulus=17:i32, polynomialModulus=#modulus>
50- %a = polynomial.constant <1 + x**2 - 3x**3> : polynomial.polynomial<#ring>
51- ```
52- }];
53-
54- let useDefaultTypePrinterParser = 1;
55- let useDefaultAttributePrinterParser = 1;
56- }
57-
58- class Polynomial_Attr<string name, string attrMnemonic, list<Trait> traits = []>
59- : AttrDef<Polynomial_Dialect, name, traits> {
60- let mnemonic = attrMnemonic;
61- }
62-
63- def Polynomial_IntPolynomialAttr : Polynomial_Attr<"IntPolynomial", "int_polynomial"> {
64- let summary = "An attribute containing a single-variable polynomial with integer coefficients.";
65- let description = [{
66- A polynomial attribute represents a single-variable polynomial with integer
67- coefficients, which is used to define the modulus of a `RingAttr`, as well
68- as to define constants and perform constant folding for `polynomial` ops.
69-
70- The polynomial must be expressed as a list of monomial terms, with addition
71- or subtraction between them. The choice of variable name is arbitrary, but
72- must be consistent across all the monomials used to define a single
73- attribute. The order of monomial terms is arbitrary, each monomial degree
74- must occur at most once.
75-
76- Example:
77-
78- ```mlir
79- #poly = #polynomial.int_polynomial<x**1024 + 1>
80- ```
81- }];
82- let parameters = (ins "::mlir::polynomial::IntPolynomial":$polynomial);
83- let hasCustomAssemblyFormat = 1;
84- }
85-
86- def Polynomial_FloatPolynomialAttr : Polynomial_Attr<"FloatPolynomial", "float_polynomial"> {
87- let summary = "An attribute containing a single-variable polynomial with double precision floating point coefficients.";
88- let description = [{
89- A polynomial attribute represents a single-variable polynomial with double
90- precision floating point coefficients.
91-
92- The polynomial must be expressed as a list of monomial terms, with addition
93- or subtraction between them. The choice of variable name is arbitrary, but
94- must be consistent across all the monomials used to define a single
95- attribute. The order of monomial terms is arbitrary, each monomial degree
96- must occur at most once.
97-
98- Example:
99-
100- ```mlir
101- #poly = #polynomial.float_polynomial<0.5 x**7 + 1.5>
102- ```
103- }];
104- let parameters = (ins "FloatPolynomial":$polynomial);
105- let hasCustomAssemblyFormat = 1;
106- }
107-
108- def Polynomial_RingAttr : Polynomial_Attr<"Ring", "ring"> {
109- let summary = "An attribute specifying a polynomial ring.";
110- let description = [{
111- A ring describes the domain in which polynomial arithmetic occurs. The ring
112- attribute in `polynomial` represents the more specific case of polynomials
113- with a single indeterminate; whose coefficients can be represented by
114- another MLIR type (`coefficientType`); and, if the coefficient type is
115- integral, whose coefficients are taken modulo some statically known modulus
116- (`coefficientModulus`).
117-
118- Additionally, a polynomial ring can specify a _polynomialModulus_, which converts
119- polynomial arithmetic to the analogue of modular integer arithmetic, where
120- each polynomial is represented as its remainder when dividing by the
121- modulus. For single-variable polynomials, an "polynomialModulus" is always specificed
122- via a single polynomial, which we call `polynomialModulus`.
123-
124- An expressive example is polynomials with i32 coefficients, whose
125- coefficients are taken modulo `2**32 - 5`, with a polynomial modulus of
126- `x**1024 - 1`.
127-
128- ```mlir
129- #poly_mod = #polynomial.int_polynomial<-1 + x**1024>
130- #ring = #polynomial.ring<coefficientType=i32,
131- coefficientModulus=4294967291:i32,
132- polynomialModulus=#poly_mod>
133-
134- %0 = ... : polynomial.polynomial<#ring>
135- ```
136-
137- In this case, the value of a polynomial is always "converted" to a
138- canonical form by applying repeated reductions by setting `x**1024 = 1`
139- and simplifying.
140-
141- The coefficient and polynomial modulus parameters are optional, and the
142- coefficient modulus is only allowed if the coefficient type is integral.
143- }];
144-
145- let parameters = (ins
146- "Type": $coefficientType,
147- OptionalParameter<"::mlir::IntegerAttr">: $coefficientModulus,
148- OptionalParameter<"::mlir::polynomial::IntPolynomialAttr">: $polynomialModulus,
149- OptionalParameter<"::mlir::IntegerAttr">: $primitiveRoot
150- );
151- let assemblyFormat = "`<` struct(params) `>`";
152- let builders = [
153- AttrBuilderWithInferredContext<
154- (ins "::mlir::Type":$coefficientTy,
155- CArg<"::mlir::IntegerAttr", "nullptr"> :$coefficientModulusAttr,
156- CArg<"::mlir::polynomial::IntPolynomialAttr", "nullptr"> :$polynomialModulusAttr,
157- CArg<"::mlir::IntegerAttr", "nullptr"> :$primitiveRootAttr), [{
158- return $_get(
159- coefficientTy.getContext(),
160- coefficientTy,
161- coefficientModulusAttr,
162- polynomialModulusAttr,
163- primitiveRootAttr);
164- }]>,
165- ];
166- }
16+ include "mlir/Dialect/Polynomial/IR/PolynomialDialect.td"
17+ include "mlir/Dialect/Polynomial/IR/PolynomialAttributes.td"
16718
16819class Polynomial_Type<string name, string typeMnemonic>
16920 : TypeDef<Polynomial_Dialect, name> {
0 commit comments