Skip to content

Arith

arith

boolLike = ContainerOf(IntegerType(1)) module-attribute

signlessIntegerLike = ContainerOf(AnyOf([IntegerType, IndexType])) module-attribute

floatingPointLike = ContainerOf(AnyFloatConstr) module-attribute

CMPI_COMPARISON_OPERATIONS = ['eq', 'ne', 'slt', 'sle', 'sgt', 'sge', 'ult', 'ule', 'ugt', 'uge'] module-attribute

CMPF_COMPARISON_OPERATIONS = ['false', 'oeq', 'ogt', 'oge', 'olt', 'ole', 'one', 'ord', 'ueq', 'ugt', 'uge', 'ult', 'ule', 'une', 'uno', 'true'] module-attribute

Arith = Dialect('arith', [ConstantOp, AddiOp, AddUIExtendedOp, SubiOp, MuliOp, MulUIExtendedOp, MulSIExtendedOp, DivUIOp, DivSIOp, FloorDivSIOp, CeilDivSIOp, CeilDivUIOp, RemUIOp, RemSIOp, MinSIOp, MaxSIOp, MinUIOp, MaxUIOp, AddfOp, SubfOp, MulfOp, DivfOp, NegfOp, CmpiOp, CmpfOp, SelectOp, AndIOp, OrIOp, XOrIOp, ShLIOp, ShRUIOp, ShRSIOp, MinimumfOp, MinnumfOp, MaximumfOp, MaxnumfOp, BitcastOp, IndexCastOp, FPToSIOp, FPToUIOp, SIToFPOp, UIToFPOp, ExtFOp, TruncFOp, TruncIOp, ExtSIOp, ExtUIOp], [FastMathFlagsAttr, IntegerOverflowAttr], [ArithConstantMaterializationInterface()]) module-attribute

FastMathFlagsAttr

Bases: FastMathAttrBase

arith.fastmath is a mirror of LLVMs fastmath flags.

Source code in xdsl/dialects/arith.py
104
105
106
107
108
109
110
111
112
113
114
115
@irdl_attr_definition
class FastMathFlagsAttr(FastMathAttrBase):
    """
    arith.fastmath is a mirror of LLVMs fastmath flags.
    """

    name = "arith.fastmath"

    def __init__(self, flags: None | Iterable[FastMathFlag] | Literal["none", "fast"]):
        # irdl_attr_definition defines an __init__ if none is defined, so we need to
        # explicitely define one here.
        super().__init__(flags)

name = 'arith.fastmath' class-attribute instance-attribute

__init__(flags: None | Iterable[FastMathFlag] | Literal['none', 'fast'])

Source code in xdsl/dialects/arith.py
112
113
114
115
def __init__(self, flags: None | Iterable[FastMathFlag] | Literal["none", "fast"]):
    # irdl_attr_definition defines an __init__ if none is defined, so we need to
    # explicitely define one here.
    super().__init__(flags)

IntegerOverflowFlag

Bases: StrEnum

Source code in xdsl/dialects/arith.py
118
119
120
class IntegerOverflowFlag(StrEnum):
    NSW = "nsw"
    NUW = "nuw"

NSW = 'nsw' class-attribute instance-attribute

NUW = 'nuw' class-attribute instance-attribute

IntegerOverflowAttr

Bases: BitEnumAttribute[IntegerOverflowFlag]

Source code in xdsl/dialects/arith.py
123
124
125
126
127
128
129
130
131
132
@irdl_attr_definition
class IntegerOverflowAttr(BitEnumAttribute[IntegerOverflowFlag]):
    name = "arith.overflow"

    none_value = "none"

    def __init__(self, flags: None | Iterable[IntegerOverflowFlag] | Literal["none"]):
        # irdl_attr_definition defines an __init__ if none is defined, so we need to
        # explicitely define one here.
        super().__init__(flags)

name = 'arith.overflow' class-attribute instance-attribute

none_value = 'none' class-attribute instance-attribute

__init__(flags: None | Iterable[IntegerOverflowFlag] | Literal['none'])

Source code in xdsl/dialects/arith.py
129
130
131
132
def __init__(self, flags: None | Iterable[IntegerOverflowFlag] | Literal["none"]):
    # irdl_attr_definition defines an __init__ if none is defined, so we need to
    # explicitely define one here.
    super().__init__(flags)

ConstantOp

Bases: IRDLOperation, HasFolderInterface

Source code in xdsl/dialects/arith.py
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
@irdl_op_definition
class ConstantOp(IRDLOperation, HasFolderInterface):
    name = "arith.constant"
    _T: ClassVar = VarConstraint("T", AnyAttr())
    result = result_def(_T)
    value = prop_def(
        IntegerAttr.constr((SignlessIntegerConstraint | IndexTypeConstr) & _T)
        | ParamAttrConstraint(FloatAttr, (AnyAttr(), _T))
        | ParamAttrConstraint(DenseIntOrFPElementsAttr, (_T, AnyAttr()))
        | ParamAttrConstraint(DenseResourceAttr, (AnyAttr(), _T))
    )

    traits = traits_def(Pure(), ConstantLike())

    assembly_format = "attr-dict $value"

    def __init__(
        self,
        value: IntegerAttr | FloatAttr | DenseIntOrFPElementsAttr | DenseResourceAttr,
        value_type: Attribute | None = None,
    ):
        if value_type is None:
            value_type = value.get_type()

        super().__init__(
            operands=[], result_types=[value_type], properties={"value": value}
        )

    @staticmethod
    def from_int_and_width(
        value: int | IntAttr,
        value_type: int | IntegerType | IndexType,
        *,
        truncate_bits: bool = False,
    ) -> ConstantOp:
        if isinstance(value_type, int):
            value_type = IntegerType(value_type)
        return ConstantOp.create(
            result_types=[value_type],
            properties={
                "value": IntegerAttr(value, value_type, truncate_bits=truncate_bits)
            },
        )

    def fold(self) -> Sequence[SSAValue | Attribute] | None:
        return (self.value,)

name = 'arith.constant' class-attribute instance-attribute

result = result_def(_T) class-attribute instance-attribute

value = prop_def(IntegerAttr.constr((SignlessIntegerConstraint | IndexTypeConstr) & _T) | ParamAttrConstraint(FloatAttr, (AnyAttr(), _T)) | ParamAttrConstraint(DenseIntOrFPElementsAttr, (_T, AnyAttr())) | ParamAttrConstraint(DenseResourceAttr, (AnyAttr(), _T))) class-attribute instance-attribute

traits = traits_def(Pure(), ConstantLike()) class-attribute instance-attribute

assembly_format = 'attr-dict $value' class-attribute instance-attribute

__init__(value: IntegerAttr | FloatAttr | DenseIntOrFPElementsAttr | DenseResourceAttr, value_type: Attribute | None = None)

Source code in xdsl/dialects/arith.py
151
152
153
154
155
156
157
158
159
160
161
def __init__(
    self,
    value: IntegerAttr | FloatAttr | DenseIntOrFPElementsAttr | DenseResourceAttr,
    value_type: Attribute | None = None,
):
    if value_type is None:
        value_type = value.get_type()

    super().__init__(
        operands=[], result_types=[value_type], properties={"value": value}
    )

from_int_and_width(value: int | IntAttr, value_type: int | IntegerType | IndexType, *, truncate_bits: bool = False) -> ConstantOp staticmethod

Source code in xdsl/dialects/arith.py
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
@staticmethod
def from_int_and_width(
    value: int | IntAttr,
    value_type: int | IntegerType | IndexType,
    *,
    truncate_bits: bool = False,
) -> ConstantOp:
    if isinstance(value_type, int):
        value_type = IntegerType(value_type)
    return ConstantOp.create(
        result_types=[value_type],
        properties={
            "value": IntegerAttr(value, value_type, truncate_bits=truncate_bits)
        },
    )

fold() -> Sequence[SSAValue | Attribute] | None

Source code in xdsl/dialects/arith.py
179
180
def fold(self) -> Sequence[SSAValue | Attribute] | None:
    return (self.value,)

SignlessIntegerBinaryOperation

Bases: IRDLOperation, HasFolderInterface, ABC

A generic base class for arith's binary operations on signless integers.

Source code in xdsl/dialects/arith.py
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
class SignlessIntegerBinaryOperation(IRDLOperation, HasFolderInterface, abc.ABC):
    """A generic base class for arith's binary operations on signless integers."""

    T: ClassVar = VarConstraint("T", signlessIntegerLike)

    lhs = operand_def(T)
    rhs = operand_def(T)
    result = result_def(T)

    assembly_format = "$lhs `,` $rhs attr-dict `:` type($result)"

    @staticmethod
    def py_operation(lhs: int, rhs: int) -> int | None:
        """
        Performs a python function corresponding to this operation.

        If `i := py_operation(lhs, rhs)` is an int, then this operation can be
        canonicalized to a constant with value `i` when the inputs are constants
        with values `lhs` and `rhs`.
        """
        return None

    @staticmethod
    def is_right_zero(attr: IntegerAttr) -> bool:
        """
        Returns True only when 'attr' is a right zero for the operation

        See external [documentation](https://en.wikipedia.org/wiki/Absorbing_element).

        Note that this depends on the operation and does *not* imply that
        attr.value.data == 0
        """
        return False

    @staticmethod
    def is_right_unit(attr: IntegerAttr) -> bool:
        """
        Return True only when 'attr' is a right unit/identity for the operation

        See external [documentation](https://en.wikipedia.org/wiki/Identity_element).
        """
        return False

    def fold(self):
        lhs = ConstantLike.get_constant_value(self.lhs)
        rhs = ConstantLike.get_constant_value(self.rhs)
        if lhs is not None and rhs is not None:
            if isa(lhs, IntegerAttr) and isa(rhs, IntegerAttr):
                assert lhs.type == rhs.type
                result = self.py_operation(lhs.value.data, rhs.value.data)
                if result is not None:
                    return (IntegerAttr(result, lhs.type, truncate_bits=True),)
        if isa(rhs, IntegerAttr) and self.is_right_unit(rhs):
            return (self.lhs,)
        if not self.has_trait(Commutative):
            return None
        if isa(lhs, IntegerAttr) and self.is_right_unit(lhs):
            return (self.rhs,)

    def __init__(
        self,
        operand1: Operation | SSAValue,
        operand2: Operation | SSAValue,
        result_type: Attribute | None = None,
    ):
        if result_type is None:
            result_type = SSAValue.get(operand1).type
        super().__init__(operands=[operand1, operand2], result_types=[result_type])

    def __hash__(self) -> int:
        return id(self)

T: ClassVar = VarConstraint('T', signlessIntegerLike) class-attribute instance-attribute

lhs = operand_def(T) class-attribute instance-attribute

rhs = operand_def(T) class-attribute instance-attribute

result = result_def(T) class-attribute instance-attribute

assembly_format = '$lhs `,` $rhs attr-dict `:` type($result)' class-attribute instance-attribute

py_operation(lhs: int, rhs: int) -> int | None staticmethod

Performs a python function corresponding to this operation.

If i := py_operation(lhs, rhs) is an int, then this operation can be canonicalized to a constant with value i when the inputs are constants with values lhs and rhs.

Source code in xdsl/dialects/arith.py
194
195
196
197
198
199
200
201
202
203
@staticmethod
def py_operation(lhs: int, rhs: int) -> int | None:
    """
    Performs a python function corresponding to this operation.

    If `i := py_operation(lhs, rhs)` is an int, then this operation can be
    canonicalized to a constant with value `i` when the inputs are constants
    with values `lhs` and `rhs`.
    """
    return None

is_right_zero(attr: IntegerAttr) -> bool staticmethod

Returns True only when 'attr' is a right zero for the operation

See external documentation.

Note that this depends on the operation and does not imply that attr.value.data == 0

Source code in xdsl/dialects/arith.py
205
206
207
208
209
210
211
212
213
214
215
@staticmethod
def is_right_zero(attr: IntegerAttr) -> bool:
    """
    Returns True only when 'attr' is a right zero for the operation

    See external [documentation](https://en.wikipedia.org/wiki/Absorbing_element).

    Note that this depends on the operation and does *not* imply that
    attr.value.data == 0
    """
    return False

is_right_unit(attr: IntegerAttr) -> bool staticmethod

Return True only when 'attr' is a right unit/identity for the operation

See external documentation.

Source code in xdsl/dialects/arith.py
217
218
219
220
221
222
223
224
@staticmethod
def is_right_unit(attr: IntegerAttr) -> bool:
    """
    Return True only when 'attr' is a right unit/identity for the operation

    See external [documentation](https://en.wikipedia.org/wiki/Identity_element).
    """
    return False

fold()

Source code in xdsl/dialects/arith.py
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
def fold(self):
    lhs = ConstantLike.get_constant_value(self.lhs)
    rhs = ConstantLike.get_constant_value(self.rhs)
    if lhs is not None and rhs is not None:
        if isa(lhs, IntegerAttr) and isa(rhs, IntegerAttr):
            assert lhs.type == rhs.type
            result = self.py_operation(lhs.value.data, rhs.value.data)
            if result is not None:
                return (IntegerAttr(result, lhs.type, truncate_bits=True),)
    if isa(rhs, IntegerAttr) and self.is_right_unit(rhs):
        return (self.lhs,)
    if not self.has_trait(Commutative):
        return None
    if isa(lhs, IntegerAttr) and self.is_right_unit(lhs):
        return (self.rhs,)

__init__(operand1: Operation | SSAValue, operand2: Operation | SSAValue, result_type: Attribute | None = None)

Source code in xdsl/dialects/arith.py
242
243
244
245
246
247
248
249
250
def __init__(
    self,
    operand1: Operation | SSAValue,
    operand2: Operation | SSAValue,
    result_type: Attribute | None = None,
):
    if result_type is None:
        result_type = SSAValue.get(operand1).type
    super().__init__(operands=[operand1, operand2], result_types=[result_type])

__hash__() -> int

Source code in xdsl/dialects/arith.py
252
253
def __hash__(self) -> int:
    return id(self)

SignlessIntegerBinaryOperationHasCanonicalizationPatternsTrait dataclass

Bases: HasCanonicalizationPatternsTrait

Source code in xdsl/dialects/arith.py
256
257
258
259
260
261
262
263
264
265
266
267
268
269
class SignlessIntegerBinaryOperationHasCanonicalizationPatternsTrait(
    HasCanonicalizationPatternsTrait
):
    @classmethod
    def get_canonicalization_patterns(cls) -> tuple[RewritePattern, ...]:
        from xdsl.transforms.canonicalization_patterns.arith import (
            SignlessIntegerBinaryOperationConstantProp,
            SignlessIntegerBinaryOperationZeroOrUnitRight,
        )

        return (
            SignlessIntegerBinaryOperationConstantProp(),
            SignlessIntegerBinaryOperationZeroOrUnitRight(),
        )

get_canonicalization_patterns() -> tuple[RewritePattern, ...] classmethod

Source code in xdsl/dialects/arith.py
259
260
261
262
263
264
265
266
267
268
269
@classmethod
def get_canonicalization_patterns(cls) -> tuple[RewritePattern, ...]:
    from xdsl.transforms.canonicalization_patterns.arith import (
        SignlessIntegerBinaryOperationConstantProp,
        SignlessIntegerBinaryOperationZeroOrUnitRight,
    )

    return (
        SignlessIntegerBinaryOperationConstantProp(),
        SignlessIntegerBinaryOperationZeroOrUnitRight(),
    )

SignlessIntegerBinaryOperationWithOverflow

Bases: SignlessIntegerBinaryOperation, ABC

A generic base class for arith's binary operations on signless integers which can overflow.

Source code in xdsl/dialects/arith.py
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
class SignlessIntegerBinaryOperationWithOverflow(
    SignlessIntegerBinaryOperation, abc.ABC
):
    """
    A generic base class for arith's binary operations on signless integers which
    can overflow.
    """

    overflow_flags = prop_def(
        IntegerOverflowAttr,
        default_value=IntegerOverflowAttr("none"),
        prop_name="overflowFlags",
    )

    assembly_format = (
        "$lhs `,` $rhs (`overflow` `` $overflowFlags^)? attr-dict `:` type($result)"
    )

    def __init__(
        self,
        operand1: Operation | SSAValue,
        operand2: Operation | SSAValue,
        result_type: Attribute | None = None,
        overflow: IntegerOverflowAttr = IntegerOverflowAttr("none"),
    ):
        if result_type is None:
            result_type = SSAValue.get(operand1).type
        IRDLOperation.__init__(
            self,
            operands=[operand1, operand2],
            properties={"overflowFlags": overflow},
            result_types=[result_type],
        )

overflow_flags = prop_def(IntegerOverflowAttr, default_value=(IntegerOverflowAttr('none')), prop_name='overflowFlags') class-attribute instance-attribute

assembly_format = '$lhs `,` $rhs (`overflow` `` $overflowFlags^)? attr-dict `:` type($result)' class-attribute instance-attribute

__init__(operand1: Operation | SSAValue, operand2: Operation | SSAValue, result_type: Attribute | None = None, overflow: IntegerOverflowAttr = IntegerOverflowAttr('none'))

Source code in xdsl/dialects/arith.py
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
def __init__(
    self,
    operand1: Operation | SSAValue,
    operand2: Operation | SSAValue,
    result_type: Attribute | None = None,
    overflow: IntegerOverflowAttr = IntegerOverflowAttr("none"),
):
    if result_type is None:
        result_type = SSAValue.get(operand1).type
    IRDLOperation.__init__(
        self,
        operands=[operand1, operand2],
        properties={"overflowFlags": overflow},
        result_types=[result_type],
    )

FloatingPointLikeBinaryOpHasCanonicalizationPatternsTrait dataclass

Bases: HasCanonicalizationPatternsTrait

Source code in xdsl/dialects/arith.py
307
308
309
310
311
312
313
314
class FloatingPointLikeBinaryOpHasCanonicalizationPatternsTrait(
    HasCanonicalizationPatternsTrait
):
    @classmethod
    def get_canonicalization_patterns(cls) -> tuple[RewritePattern, ...]:
        from xdsl.transforms.canonicalization_patterns.arith import FoldConstConstOp

        return (FoldConstConstOp(),)

get_canonicalization_patterns() -> tuple[RewritePattern, ...] classmethod

Source code in xdsl/dialects/arith.py
310
311
312
313
314
@classmethod
def get_canonicalization_patterns(cls) -> tuple[RewritePattern, ...]:
    from xdsl.transforms.canonicalization_patterns.arith import FoldConstConstOp

    return (FoldConstConstOp(),)

FloatingPointLikeBinaryOpHasFastReassociativeCanonicalizationPatternsTrait dataclass

Bases: HasCanonicalizationPatternsTrait

Source code in xdsl/dialects/arith.py
317
318
319
320
321
322
323
324
325
326
327
class FloatingPointLikeBinaryOpHasFastReassociativeCanonicalizationPatternsTrait(
    HasCanonicalizationPatternsTrait
):
    @classmethod
    def get_canonicalization_patterns(cls) -> tuple[RewritePattern, ...]:
        from xdsl.transforms.canonicalization_patterns.arith import (
            FoldConstConstOp,
            FoldConstsByReassociation,
        )

        return FoldConstsByReassociation(), FoldConstConstOp()

get_canonicalization_patterns() -> tuple[RewritePattern, ...] classmethod

Source code in xdsl/dialects/arith.py
320
321
322
323
324
325
326
327
@classmethod
def get_canonicalization_patterns(cls) -> tuple[RewritePattern, ...]:
    from xdsl.transforms.canonicalization_patterns.arith import (
        FoldConstConstOp,
        FoldConstsByReassociation,
    )

    return FoldConstsByReassociation(), FoldConstConstOp()

FloatingPointLikeBinaryOperation

Bases: IRDLOperation, ABC

A generic base class for arith's binary operations on floats.

Source code in xdsl/dialects/arith.py
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
class FloatingPointLikeBinaryOperation(IRDLOperation, abc.ABC):
    """A generic base class for arith's binary operations on floats."""

    T: ClassVar = VarConstraint("T", floatingPointLike)

    lhs = operand_def(T)
    rhs = operand_def(T)
    result = result_def(T)

    fastmath = prop_def(FastMathFlagsAttr, default_value=FastMathFlagsAttr("none"))

    def __init__(
        self,
        operand1: Operation | SSAValue,
        operand2: Operation | SSAValue,
        flags: FastMathFlagsAttr | None = None,
        result_type: Attribute | None = None,
    ):
        if result_type is None:
            result_type = SSAValue.get(operand1).type
        super().__init__(
            operands=[operand1, operand2],
            result_types=[result_type],
            properties={"fastmath": flags},
        )

    assembly_format = (
        "$lhs `,` $rhs (`fastmath` `` $fastmath^)? attr-dict `:` type($result)"
    )

T: ClassVar = VarConstraint('T', floatingPointLike) class-attribute instance-attribute

lhs = operand_def(T) class-attribute instance-attribute

rhs = operand_def(T) class-attribute instance-attribute

result = result_def(T) class-attribute instance-attribute

fastmath = prop_def(FastMathFlagsAttr, default_value=(FastMathFlagsAttr('none'))) class-attribute instance-attribute

assembly_format = '$lhs `,` $rhs (`fastmath` `` $fastmath^)? attr-dict `:` type($result)' class-attribute instance-attribute

__init__(operand1: Operation | SSAValue, operand2: Operation | SSAValue, flags: FastMathFlagsAttr | None = None, result_type: Attribute | None = None)

Source code in xdsl/dialects/arith.py
341
342
343
344
345
346
347
348
349
350
351
352
353
354
def __init__(
    self,
    operand1: Operation | SSAValue,
    operand2: Operation | SSAValue,
    flags: FastMathFlagsAttr | None = None,
    result_type: Attribute | None = None,
):
    if result_type is None:
        result_type = SSAValue.get(operand1).type
    super().__init__(
        operands=[operand1, operand2],
        result_types=[result_type],
        properties={"fastmath": flags},
    )

AddiOp dataclass

Bases: SignlessIntegerBinaryOperationWithOverflow

Source code in xdsl/dialects/arith.py
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
@irdl_op_definition
class AddiOp(SignlessIntegerBinaryOperationWithOverflow):
    name = "arith.addi"

    traits = traits_def(
        Pure(),
        Commutative(),
        SignlessIntegerBinaryOperationHasCanonicalizationPatternsTrait(),
    )

    @staticmethod
    def py_operation(lhs: int, rhs: int) -> int | None:
        return lhs + rhs

    @staticmethod
    def is_right_unit(attr: IntegerAttr) -> bool:
        return attr.value.data == 0

name = 'arith.addi' class-attribute instance-attribute

traits = traits_def(Pure(), Commutative(), SignlessIntegerBinaryOperationHasCanonicalizationPatternsTrait()) class-attribute instance-attribute

py_operation(lhs: int, rhs: int) -> int | None staticmethod

Source code in xdsl/dialects/arith.py
371
372
373
@staticmethod
def py_operation(lhs: int, rhs: int) -> int | None:
    return lhs + rhs

is_right_unit(attr: IntegerAttr) -> bool staticmethod

Source code in xdsl/dialects/arith.py
375
376
377
@staticmethod
def is_right_unit(attr: IntegerAttr) -> bool:
    return attr.value.data == 0

AddUIExtendedOp

Bases: IRDLOperation

An add operation on an unsigned representation of integers that returns a flag indicating if the result overflowed.

Source code in xdsl/dialects/arith.py
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
@irdl_op_definition
class AddUIExtendedOp(IRDLOperation):
    """
    An add operation on an unsigned representation of integers that returns a flag
    indicating if the result overflowed.
    """

    name = "arith.addui_extended"

    traits = traits_def(Pure())

    T: ClassVar = VarConstraint("T", signlessIntegerLike)

    lhs = operand_def(T)
    rhs = operand_def(T)

    sum = result_def(T)
    overflow = result_def(boolLike)

    assembly_format = "$lhs `,` $rhs attr-dict `:` type($sum) `,` type($overflow)"

    traits = traits_def(Pure())

    def __init__(
        self,
        operand1: Operation | SSAValue,
        operand2: Operation | SSAValue,
        attributes: Mapping[str, Attribute] | None = None,
        result_type: Attribute | None = None,
    ):
        if result_type is None:
            result_type = SSAValue.get(operand1).type
        overflow_type = AddUIExtendedOp.infer_overflow_type(result_type)
        super().__init__(
            operands=[operand1, operand2],
            result_types=[result_type, overflow_type],
            attributes=attributes,
        )

    def verify_(self):
        expected_overflow_type = AddUIExtendedOp.infer_overflow_type(self.lhs.type)
        if self.overflow.type != expected_overflow_type:
            raise VerifyException(
                f"overflow type {self.overflow.type} does not "
                f"match input types {self.lhs.type}. Expected {expected_overflow_type}"
            )

    @staticmethod
    def infer_overflow_type(input_type: Attribute) -> Attribute:
        if isinstance(input_type, IntegerType):
            return IntegerType(1)
        if isinstance(input_type, VectorType):
            return VectorType(
                IntegerType(1), input_type.shape, input_type.scalable_dims
            )
        if isinstance(input_type, UnrankedTensorType):
            return UnrankedTensorType(IntegerType(1))
        if isinstance(input_type, TensorType):
            return TensorType(IntegerType(1), input_type.shape, input_type.encoding)
        raise ValueError(
            f"Unsupported input type for {AddUIExtendedOp.name}: {input_type}"
        )

name = 'arith.addui_extended' class-attribute instance-attribute

T: ClassVar = VarConstraint('T', signlessIntegerLike) class-attribute instance-attribute

lhs = operand_def(T) class-attribute instance-attribute

rhs = operand_def(T) class-attribute instance-attribute

sum = result_def(T) class-attribute instance-attribute

overflow = result_def(boolLike) class-attribute instance-attribute

assembly_format = '$lhs `,` $rhs attr-dict `:` type($sum) `,` type($overflow)' class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

__init__(operand1: Operation | SSAValue, operand2: Operation | SSAValue, attributes: Mapping[str, Attribute] | None = None, result_type: Attribute | None = None)

Source code in xdsl/dialects/arith.py
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
def __init__(
    self,
    operand1: Operation | SSAValue,
    operand2: Operation | SSAValue,
    attributes: Mapping[str, Attribute] | None = None,
    result_type: Attribute | None = None,
):
    if result_type is None:
        result_type = SSAValue.get(operand1).type
    overflow_type = AddUIExtendedOp.infer_overflow_type(result_type)
    super().__init__(
        operands=[operand1, operand2],
        result_types=[result_type, overflow_type],
        attributes=attributes,
    )

verify_()

Source code in xdsl/dialects/arith.py
419
420
421
422
423
424
425
def verify_(self):
    expected_overflow_type = AddUIExtendedOp.infer_overflow_type(self.lhs.type)
    if self.overflow.type != expected_overflow_type:
        raise VerifyException(
            f"overflow type {self.overflow.type} does not "
            f"match input types {self.lhs.type}. Expected {expected_overflow_type}"
        )

infer_overflow_type(input_type: Attribute) -> Attribute staticmethod

Source code in xdsl/dialects/arith.py
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
@staticmethod
def infer_overflow_type(input_type: Attribute) -> Attribute:
    if isinstance(input_type, IntegerType):
        return IntegerType(1)
    if isinstance(input_type, VectorType):
        return VectorType(
            IntegerType(1), input_type.shape, input_type.scalable_dims
        )
    if isinstance(input_type, UnrankedTensorType):
        return UnrankedTensorType(IntegerType(1))
    if isinstance(input_type, TensorType):
        return TensorType(IntegerType(1), input_type.shape, input_type.encoding)
    raise ValueError(
        f"Unsupported input type for {AddUIExtendedOp.name}: {input_type}"
    )

MuliOp dataclass

Bases: SignlessIntegerBinaryOperationWithOverflow

Source code in xdsl/dialects/arith.py
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
@irdl_op_definition
class MuliOp(SignlessIntegerBinaryOperationWithOverflow):
    name = "arith.muli"

    traits = traits_def(
        Pure(),
        Commutative(),
        SignlessIntegerBinaryOperationHasCanonicalizationPatternsTrait(),
    )

    @staticmethod
    def py_operation(lhs: int, rhs: int) -> int | None:
        return lhs * rhs

    @staticmethod
    def is_right_unit(attr: IntegerAttr) -> bool:
        return attr == IntegerAttr(1, attr.type)

    @staticmethod
    def is_right_zero(attr: IntegerAttr) -> bool:
        return attr.value.data == 0

name = 'arith.muli' class-attribute instance-attribute

traits = traits_def(Pure(), Commutative(), SignlessIntegerBinaryOperationHasCanonicalizationPatternsTrait()) class-attribute instance-attribute

py_operation(lhs: int, rhs: int) -> int | None staticmethod

Source code in xdsl/dialects/arith.py
454
455
456
@staticmethod
def py_operation(lhs: int, rhs: int) -> int | None:
    return lhs * rhs

is_right_unit(attr: IntegerAttr) -> bool staticmethod

Source code in xdsl/dialects/arith.py
458
459
460
@staticmethod
def is_right_unit(attr: IntegerAttr) -> bool:
    return attr == IntegerAttr(1, attr.type)

is_right_zero(attr: IntegerAttr) -> bool staticmethod

Source code in xdsl/dialects/arith.py
462
463
464
@staticmethod
def is_right_zero(attr: IntegerAttr) -> bool:
    return attr.value.data == 0

MulExtendedBase

Bases: IRDLOperation

Base class for extended multiplication operations.

Source code in xdsl/dialects/arith.py
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
class MulExtendedBase(IRDLOperation):
    """Base class for extended multiplication operations."""

    T: ClassVar = VarConstraint("T", signlessIntegerLike)

    lhs = operand_def(T)
    rhs = operand_def(T)
    low = result_def(T)
    high = result_def(T)

    traits = traits_def(Pure())

    def __init__(
        self,
        operand1: SSAValue,
        operand2: SSAValue,
        result_type: Attribute | None = None,
    ):
        if result_type is None:
            result_type = SSAValue.get(operand1).type
        super().__init__(
            operands=[operand1, operand2], result_types=[result_type, result_type]
        )

    assembly_format = "$lhs `,` $rhs attr-dict `:` type($lhs)"

T: ClassVar = VarConstraint('T', signlessIntegerLike) class-attribute instance-attribute

lhs = operand_def(T) class-attribute instance-attribute

rhs = operand_def(T) class-attribute instance-attribute

low = result_def(T) class-attribute instance-attribute

high = result_def(T) class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

assembly_format = '$lhs `,` $rhs attr-dict `:` type($lhs)' class-attribute instance-attribute

__init__(operand1: SSAValue, operand2: SSAValue, result_type: Attribute | None = None)

Source code in xdsl/dialects/arith.py
479
480
481
482
483
484
485
486
487
488
489
def __init__(
    self,
    operand1: SSAValue,
    operand2: SSAValue,
    result_type: Attribute | None = None,
):
    if result_type is None:
        result_type = SSAValue.get(operand1).type
    super().__init__(
        operands=[operand1, operand2], result_types=[result_type, result_type]
    )

MulUIExtendedOp dataclass

Bases: MulExtendedBase

Extended unsigned integer multiplication operation.

Source code in xdsl/dialects/arith.py
494
495
496
497
498
@irdl_op_definition
class MulUIExtendedOp(MulExtendedBase):
    """Extended unsigned integer multiplication operation."""

    name = "arith.mului_extended"

name = 'arith.mului_extended' class-attribute instance-attribute

MulSIExtendedOp dataclass

Bases: MulExtendedBase

Extended unsigned integer multiplication operation.

Source code in xdsl/dialects/arith.py
501
502
503
504
505
@irdl_op_definition
class MulSIExtendedOp(MulExtendedBase):
    """Extended unsigned integer multiplication operation."""

    name = "arith.mulsi_extended"

name = 'arith.mulsi_extended' class-attribute instance-attribute

SubiOp dataclass

Bases: SignlessIntegerBinaryOperationWithOverflow

Source code in xdsl/dialects/arith.py
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
@irdl_op_definition
class SubiOp(SignlessIntegerBinaryOperationWithOverflow):
    name = "arith.subi"

    traits = traits_def(
        Pure(), SignlessIntegerBinaryOperationHasCanonicalizationPatternsTrait()
    )

    @staticmethod
    def py_operation(lhs: int, rhs: int) -> int | None:
        return lhs - rhs

    @staticmethod
    def is_right_unit(attr: IntegerAttr) -> bool:
        return attr.value.data == 0

name = 'arith.subi' class-attribute instance-attribute

traits = traits_def(Pure(), SignlessIntegerBinaryOperationHasCanonicalizationPatternsTrait()) class-attribute instance-attribute

py_operation(lhs: int, rhs: int) -> int | None staticmethod

Source code in xdsl/dialects/arith.py
516
517
518
@staticmethod
def py_operation(lhs: int, rhs: int) -> int | None:
    return lhs - rhs

is_right_unit(attr: IntegerAttr) -> bool staticmethod

Source code in xdsl/dialects/arith.py
520
521
522
@staticmethod
def is_right_unit(attr: IntegerAttr) -> bool:
    return attr.value.data == 0

DivUIOp dataclass

Bases: SignlessIntegerBinaryOperation, ConditionallySpeculatableInterface

Unsigned integer division. Rounds towards zero. Treats the leading bit as the most significant, i.e. for i16 given two's complement representation, 6 / -2 = 6 / (2^16 - 2) = 0.

Source code in xdsl/dialects/arith.py
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
@irdl_op_definition
class DivUIOp(SignlessIntegerBinaryOperation, ConditionallySpeculatableInterface):
    """
    Unsigned integer division. Rounds towards zero. Treats the leading bit as
    the most significant, i.e. for `i16` given two's complement representation,
    `6 / -2 = 6 / (2^16 - 2) = 0`.
    """

    name = "arith.divui"

    traits = traits_def(
        NoMemoryEffect(),
        SignlessIntegerBinaryOperationHasCanonicalizationPatternsTrait(),
    )

    def is_speculatable(self) -> bool:
        rhs = ConstantLike.get_constant_value(self.rhs)
        return isa(rhs, IntegerAttr[IntegerType | IndexType]) and rhs.value.data != 0

    @staticmethod
    def is_right_unit(attr: IntegerAttr) -> bool:
        return attr == IntegerAttr(1, attr.type)

name = 'arith.divui' class-attribute instance-attribute

traits = traits_def(NoMemoryEffect(), SignlessIntegerBinaryOperationHasCanonicalizationPatternsTrait()) class-attribute instance-attribute

is_speculatable() -> bool

Source code in xdsl/dialects/arith.py
540
541
542
def is_speculatable(self) -> bool:
    rhs = ConstantLike.get_constant_value(self.rhs)
    return isa(rhs, IntegerAttr[IntegerType | IndexType]) and rhs.value.data != 0

is_right_unit(attr: IntegerAttr) -> bool staticmethod

Source code in xdsl/dialects/arith.py
544
545
546
@staticmethod
def is_right_unit(attr: IntegerAttr) -> bool:
    return attr == IntegerAttr(1, attr.type)

DivSIOp dataclass

Bases: SignlessIntegerBinaryOperation, ConditionallySpeculatableInterface

Signed integer division. Rounds towards zero. Treats the leading bit as sign, i.e. 6 / -2 = -3.

Source code in xdsl/dialects/arith.py
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
@irdl_op_definition
class DivSIOp(SignlessIntegerBinaryOperation, ConditionallySpeculatableInterface):
    """
    Signed integer division. Rounds towards zero. Treats the leading bit as
    sign, i.e. `6 / -2 = -3`.
    """

    name = "arith.divsi"

    traits = traits_def(
        NoMemoryEffect(),
        SignlessIntegerBinaryOperationHasCanonicalizationPatternsTrait(),
    )

    def is_speculatable(self) -> bool:
        rhs = ConstantLike.get_constant_value(self.rhs)
        return (
            isa(rhs, IntegerAttr[IntegerType | IndexType])
            and rhs.value.data != 0
            and rhs.value.data != -1
        )

    @staticmethod
    def is_right_unit(attr: IntegerAttr) -> bool:
        return attr == IntegerAttr(1, attr.type)

name = 'arith.divsi' class-attribute instance-attribute

traits = traits_def(NoMemoryEffect(), SignlessIntegerBinaryOperationHasCanonicalizationPatternsTrait()) class-attribute instance-attribute

is_speculatable() -> bool

Source code in xdsl/dialects/arith.py
563
564
565
566
567
568
569
def is_speculatable(self) -> bool:
    rhs = ConstantLike.get_constant_value(self.rhs)
    return (
        isa(rhs, IntegerAttr[IntegerType | IndexType])
        and rhs.value.data != 0
        and rhs.value.data != -1
    )

is_right_unit(attr: IntegerAttr) -> bool staticmethod

Source code in xdsl/dialects/arith.py
571
572
573
@staticmethod
def is_right_unit(attr: IntegerAttr) -> bool:
    return attr == IntegerAttr(1, attr.type)

FloorDivSIOp dataclass

Bases: SignlessIntegerBinaryOperation

Signed floor integer division. Rounds towards negative infinity i.e. 5 / -2 = -3.

Source code in xdsl/dialects/arith.py
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
@irdl_op_definition
class FloorDivSIOp(SignlessIntegerBinaryOperation):
    """
    Signed floor integer division. Rounds towards negative infinity i.e. `5 / -2 = -3`.
    """

    name = "arith.floordivsi"

    traits = traits_def(
        Pure(), SignlessIntegerBinaryOperationHasCanonicalizationPatternsTrait()
    )

    @staticmethod
    def is_right_unit(attr: IntegerAttr) -> bool:
        return attr == IntegerAttr(1, attr.type)

name = 'arith.floordivsi' class-attribute instance-attribute

traits = traits_def(Pure(), SignlessIntegerBinaryOperationHasCanonicalizationPatternsTrait()) class-attribute instance-attribute

is_right_unit(attr: IntegerAttr) -> bool staticmethod

Source code in xdsl/dialects/arith.py
588
589
590
@staticmethod
def is_right_unit(attr: IntegerAttr) -> bool:
    return attr == IntegerAttr(1, attr.type)

CeilDivSIOp dataclass

Bases: SignlessIntegerBinaryOperation

Source code in xdsl/dialects/arith.py
593
594
595
596
597
598
599
600
601
602
603
@irdl_op_definition
class CeilDivSIOp(SignlessIntegerBinaryOperation):
    name = "arith.ceildivsi"

    traits = traits_def(
        Pure(), SignlessIntegerBinaryOperationHasCanonicalizationPatternsTrait()
    )

    @staticmethod
    def is_right_unit(attr: IntegerAttr) -> bool:
        return attr == IntegerAttr(1, attr.type)

name = 'arith.ceildivsi' class-attribute instance-attribute

traits = traits_def(Pure(), SignlessIntegerBinaryOperationHasCanonicalizationPatternsTrait()) class-attribute instance-attribute

is_right_unit(attr: IntegerAttr) -> bool staticmethod

Source code in xdsl/dialects/arith.py
601
602
603
@staticmethod
def is_right_unit(attr: IntegerAttr) -> bool:
    return attr == IntegerAttr(1, attr.type)

CeilDivUIOp dataclass

Bases: SignlessIntegerBinaryOperation

Source code in xdsl/dialects/arith.py
606
607
608
609
610
611
612
613
614
615
616
617
@irdl_op_definition
class CeilDivUIOp(SignlessIntegerBinaryOperation):
    name = "arith.ceildivui"

    traits = traits_def(
        NoMemoryEffect(),
        SignlessIntegerBinaryOperationHasCanonicalizationPatternsTrait(),
    )

    @staticmethod
    def is_right_unit(attr: IntegerAttr) -> bool:
        return attr == IntegerAttr(1, attr.type)

name = 'arith.ceildivui' class-attribute instance-attribute

traits = traits_def(NoMemoryEffect(), SignlessIntegerBinaryOperationHasCanonicalizationPatternsTrait()) class-attribute instance-attribute

is_right_unit(attr: IntegerAttr) -> bool staticmethod

Source code in xdsl/dialects/arith.py
615
616
617
@staticmethod
def is_right_unit(attr: IntegerAttr) -> bool:
    return attr == IntegerAttr(1, attr.type)

RemUIOp dataclass

Bases: SignlessIntegerBinaryOperation

Source code in xdsl/dialects/arith.py
620
621
622
@irdl_op_definition
class RemUIOp(SignlessIntegerBinaryOperation):
    name = "arith.remui"

name = 'arith.remui' class-attribute instance-attribute

RemSIOp dataclass

Bases: SignlessIntegerBinaryOperation

Source code in xdsl/dialects/arith.py
625
626
627
628
629
@irdl_op_definition
class RemSIOp(SignlessIntegerBinaryOperation):
    name = "arith.remsi"

    traits = traits_def(Pure())

name = 'arith.remsi' class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

MinUIOp dataclass

Bases: SignlessIntegerBinaryOperation

Source code in xdsl/dialects/arith.py
632
633
634
635
636
@irdl_op_definition
class MinUIOp(SignlessIntegerBinaryOperation):
    name = "arith.minui"

    traits = traits_def(Pure())

name = 'arith.minui' class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

MaxUIOp dataclass

Bases: SignlessIntegerBinaryOperation

Source code in xdsl/dialects/arith.py
639
640
641
642
643
@irdl_op_definition
class MaxUIOp(SignlessIntegerBinaryOperation):
    name = "arith.maxui"

    traits = traits_def(Pure())

name = 'arith.maxui' class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

MinSIOp dataclass

Bases: SignlessIntegerBinaryOperation

Source code in xdsl/dialects/arith.py
646
647
648
649
650
@irdl_op_definition
class MinSIOp(SignlessIntegerBinaryOperation):
    name = "arith.minsi"

    traits = traits_def(Pure())

name = 'arith.minsi' class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

MaxSIOp dataclass

Bases: SignlessIntegerBinaryOperation

Source code in xdsl/dialects/arith.py
653
654
655
656
657
@irdl_op_definition
class MaxSIOp(SignlessIntegerBinaryOperation):
    name = "arith.maxsi"

    traits = traits_def(Pure())

name = 'arith.maxsi' class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

AndIOp dataclass

Bases: SignlessIntegerBinaryOperation

Source code in xdsl/dialects/arith.py
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
@irdl_op_definition
class AndIOp(SignlessIntegerBinaryOperation):
    name = "arith.andi"

    traits = traits_def(
        Pure(),
        Commutative(),
        SignlessIntegerBinaryOperationHasCanonicalizationPatternsTrait(),
    )

    @staticmethod
    def py_operation(lhs: int, rhs: int) -> int | None:
        return lhs & rhs

    @staticmethod
    def is_right_zero(attr: IntegerAttr) -> bool:
        return attr.value.data == 0

name = 'arith.andi' class-attribute instance-attribute

traits = traits_def(Pure(), Commutative(), SignlessIntegerBinaryOperationHasCanonicalizationPatternsTrait()) class-attribute instance-attribute

py_operation(lhs: int, rhs: int) -> int | None staticmethod

Source code in xdsl/dialects/arith.py
670
671
672
@staticmethod
def py_operation(lhs: int, rhs: int) -> int | None:
    return lhs & rhs

is_right_zero(attr: IntegerAttr) -> bool staticmethod

Source code in xdsl/dialects/arith.py
674
675
676
@staticmethod
def is_right_zero(attr: IntegerAttr) -> bool:
    return attr.value.data == 0

OrIOp dataclass

Bases: SignlessIntegerBinaryOperation

Source code in xdsl/dialects/arith.py
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
@irdl_op_definition
class OrIOp(SignlessIntegerBinaryOperation):
    name = "arith.ori"

    traits = traits_def(
        Pure(),
        Commutative(),
        SignlessIntegerBinaryOperationHasCanonicalizationPatternsTrait(),
    )

    @staticmethod
    def py_operation(lhs: int, rhs: int) -> int | None:
        return lhs | rhs

    @staticmethod
    def is_right_unit(attr: IntegerAttr) -> bool:
        return attr.value.data == 0

name = 'arith.ori' class-attribute instance-attribute

traits = traits_def(Pure(), Commutative(), SignlessIntegerBinaryOperationHasCanonicalizationPatternsTrait()) class-attribute instance-attribute

py_operation(lhs: int, rhs: int) -> int | None staticmethod

Source code in xdsl/dialects/arith.py
689
690
691
@staticmethod
def py_operation(lhs: int, rhs: int) -> int | None:
    return lhs | rhs

is_right_unit(attr: IntegerAttr) -> bool staticmethod

Source code in xdsl/dialects/arith.py
693
694
695
@staticmethod
def is_right_unit(attr: IntegerAttr) -> bool:
    return attr.value.data == 0

XOrIOp dataclass

Bases: SignlessIntegerBinaryOperation

Source code in xdsl/dialects/arith.py
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
@irdl_op_definition
class XOrIOp(SignlessIntegerBinaryOperation):
    name = "arith.xori"

    traits = traits_def(
        Pure(),
        Commutative(),
        SignlessIntegerBinaryOperationHasCanonicalizationPatternsTrait(),
    )

    @staticmethod
    def py_operation(lhs: int, rhs: int) -> int | None:
        return lhs ^ rhs

    @staticmethod
    def is_right_unit(attr: IntegerAttr) -> bool:
        return attr.value.data == 0

name = 'arith.xori' class-attribute instance-attribute

traits = traits_def(Pure(), Commutative(), SignlessIntegerBinaryOperationHasCanonicalizationPatternsTrait()) class-attribute instance-attribute

py_operation(lhs: int, rhs: int) -> int | None staticmethod

Source code in xdsl/dialects/arith.py
708
709
710
@staticmethod
def py_operation(lhs: int, rhs: int) -> int | None:
    return lhs ^ rhs

is_right_unit(attr: IntegerAttr) -> bool staticmethod

Source code in xdsl/dialects/arith.py
712
713
714
@staticmethod
def is_right_unit(attr: IntegerAttr) -> bool:
    return attr.value.data == 0

ShLIOp dataclass

Bases: SignlessIntegerBinaryOperationWithOverflow

The shli operation shifts an integer value to the left by a variable amount. The low order bits are filled with zeros.

Source code in xdsl/dialects/arith.py
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
@irdl_op_definition
class ShLIOp(SignlessIntegerBinaryOperationWithOverflow):
    """
    The `shli` operation shifts an integer value to the left by a variable
    amount. The low order bits are filled with zeros.
    """

    name = "arith.shli"

    traits = traits_def(
        Pure(), SignlessIntegerBinaryOperationHasCanonicalizationPatternsTrait()
    )

    @staticmethod
    def is_right_unit(attr: IntegerAttr) -> bool:
        return attr.value.data == 0

name = 'arith.shli' class-attribute instance-attribute

traits = traits_def(Pure(), SignlessIntegerBinaryOperationHasCanonicalizationPatternsTrait()) class-attribute instance-attribute

is_right_unit(attr: IntegerAttr) -> bool staticmethod

Source code in xdsl/dialects/arith.py
730
731
732
@staticmethod
def is_right_unit(attr: IntegerAttr) -> bool:
    return attr.value.data == 0

ShRUIOp dataclass

Bases: SignlessIntegerBinaryOperation

The shrui operation shifts an integer value to the right by a variable amount. The integer is interpreted as unsigned. The high order bits are always filled with zeros.

Source code in xdsl/dialects/arith.py
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
@irdl_op_definition
class ShRUIOp(SignlessIntegerBinaryOperation):
    """
    The `shrui` operation shifts an integer value to the right by a variable
    amount. The integer is interpreted as unsigned. The high order bits are
    always filled with zeros.
    """

    name = "arith.shrui"

    traits = traits_def(
        Pure(), SignlessIntegerBinaryOperationHasCanonicalizationPatternsTrait()
    )

    @staticmethod
    def is_right_unit(attr: IntegerAttr) -> bool:
        return attr.value.data == 0

name = 'arith.shrui' class-attribute instance-attribute

traits = traits_def(Pure(), SignlessIntegerBinaryOperationHasCanonicalizationPatternsTrait()) class-attribute instance-attribute

is_right_unit(attr: IntegerAttr) -> bool staticmethod

Source code in xdsl/dialects/arith.py
749
750
751
@staticmethod
def is_right_unit(attr: IntegerAttr) -> bool:
    return attr.value.data == 0

ShRSIOp dataclass

Bases: SignlessIntegerBinaryOperation

The shrsi operation shifts an integer value to the right by a variable amount. The integer is interpreted as signed. The high order bits in the output are filled with copies of the most-significant bit of the shifted value (which means that the sign of the value is preserved).

Source code in xdsl/dialects/arith.py
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
@irdl_op_definition
class ShRSIOp(SignlessIntegerBinaryOperation):
    """
    The `shrsi` operation shifts an integer value to the right by a variable
    amount. The integer is interpreted as signed. The high order bits in the
    output are filled with copies of the most-significant bit of the shifted
    value (which means that the sign of the value is preserved).
    """

    name = "arith.shrsi"

    traits = traits_def(
        Pure(), SignlessIntegerBinaryOperationHasCanonicalizationPatternsTrait()
    )

    @staticmethod
    def is_right_unit(attr: IntegerAttr) -> bool:
        return attr.value.data == 0

name = 'arith.shrsi' class-attribute instance-attribute

traits = traits_def(Pure(), SignlessIntegerBinaryOperationHasCanonicalizationPatternsTrait()) class-attribute instance-attribute

is_right_unit(attr: IntegerAttr) -> bool staticmethod

Source code in xdsl/dialects/arith.py
769
770
771
@staticmethod
def is_right_unit(attr: IntegerAttr) -> bool:
    return attr.value.data == 0

ComparisonOperation dataclass

Bases: IRDLOperation

A generic comparison operation, operation definitions inherit this class.

The first argument to these comparison operations is the type of comparison being performed, the following comparisons are supported:

  • equal (mnemonic: "eq"; integer value: 0)
  • not equal (mnemonic: "ne"; integer value: 1)
  • signed less than (mnemonic: "slt"; integer value: 2)
  • signed less than or equal (mnemonic: "sle"; integer value: 3)
  • signed greater than (mnemonic: "sgt"; integer value: 4)
  • signed greater than or equal (mnemonic: "sge"; integer value: 5)
  • unsigned less than (mnemonic: "ult"; integer value: 6)
  • unsigned less than or equal (mnemonic: "ule"; integer value: 7)
  • unsigned greater than (mnemonic: "ugt"; integer value: 8)
  • unsigned greater than or equal (mnemonic: "uge"; integer value: 9)
Source code in xdsl/dialects/arith.py
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
class ComparisonOperation(IRDLOperation):
    """
    A generic comparison operation, operation definitions inherit this class.

    The first argument to these comparison operations is the type of comparison
    being performed, the following comparisons are supported:

    -   equal (mnemonic: `"eq"`; integer value: `0`)
    -   not equal (mnemonic: `"ne"`; integer value: `1`)
    -   signed less than (mnemonic: `"slt"`; integer value: `2`)
    -   signed less than or equal (mnemonic: `"sle"`; integer value: `3`)
    -   signed greater than (mnemonic: `"sgt"`; integer value: `4`)
    -   signed greater than or equal (mnemonic: `"sge"`; integer value: `5`)
    -   unsigned less than (mnemonic: `"ult"`; integer value: `6`)
    -   unsigned less than or equal (mnemonic: `"ule"`; integer value: `7`)
    -   unsigned greater than (mnemonic: `"ugt"`; integer value: `8`)
    -   unsigned greater than or equal (mnemonic: `"uge"`; integer value: `9`)
    """

    @staticmethod
    def _get_comparison_predicate(
        mnemonic: str, comparison_operations: dict[str, int]
    ) -> int:
        if mnemonic in comparison_operations:
            return comparison_operations[mnemonic]
        else:
            raise VerifyException(f"Unknown comparison mnemonic: {mnemonic}")

    @staticmethod
    def _validate_operand_types(operand1: SSAValue, operand2: SSAValue):
        if operand1.type != operand2.type:
            raise TypeError(
                f"Comparison operands must have same type, but "
                f"provided {operand1.type} and {operand2.type}"
            )

    traits = traits_def(Pure())

traits = traits_def(Pure()) class-attribute instance-attribute

CmpiHasCanonicalizationPatterns dataclass

Bases: HasCanonicalizationPatternsTrait

Source code in xdsl/dialects/arith.py
813
814
815
816
817
818
class CmpiHasCanonicalizationPatterns(HasCanonicalizationPatternsTrait):
    @classmethod
    def get_canonicalization_patterns(cls) -> tuple[RewritePattern, ...]:
        from xdsl.transforms.canonicalization_patterns import arith

        return (arith.ApplyCmpiPredicateToEqualOperands(),)

get_canonicalization_patterns() -> tuple[RewritePattern, ...] classmethod

Source code in xdsl/dialects/arith.py
814
815
816
817
818
@classmethod
def get_canonicalization_patterns(cls) -> tuple[RewritePattern, ...]:
    from xdsl.transforms.canonicalization_patterns import arith

    return (arith.ApplyCmpiPredicateToEqualOperands(),)

CmpiOp

Bases: ComparisonOperation

The cmpi operation is a generic comparison for integer-like types. Its two arguments can be integers, vectors or tensors thereof as long as their types match. The operation produces an i1 for the former case, a vector or a tensor of i1 with the same shape as inputs in the other cases.

The result is 1 if the comparison is true and 0 otherwise. For vector or tensor operands, the comparison is performed elementwise and the element of the result indicates whether the comparison is true for the operand elements with the same indices as those of the result.

Example:

// Custom form of scalar "signed less than" comparison. %x = arith.cmpi slt, %lhs, %rhs : i32

// Generic form of the same operation. %x = "arith.cmpi"(%lhs, %rhs) {predicate = 2 : i64} : (i32, i32) -> i1

// Custom form of vector equality comparison. %x = arith.cmpi eq, %lhs, %rhs : vector<4xi64>

// Generic form of the same operation. %x = "arith.cmpi"(%lhs, %rhs) {predicate = 0 : i64} : (vector<4xi64>, vector<4xi64>) -> vector<4xi1>

Source code in xdsl/dialects/arith.py
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
@irdl_op_definition
class CmpiOp(ComparisonOperation):
    """
    The cmpi operation is a generic comparison for integer-like types. Its two
    arguments can be integers, vectors or tensors thereof as long as their types
    match. The operation produces an i1 for the former case, a vector or a
    tensor of i1 with the same shape as inputs in the other cases.

    The result is `1` if the comparison is true and `0` otherwise. For vector or
    tensor operands, the comparison is performed elementwise and the element of
    the result indicates whether the comparison is true for the operand elements
    with the same indices as those of the result.

    Example:

    // Custom form of scalar "signed less than" comparison.
    %x = arith.cmpi slt, %lhs, %rhs : i32

    // Generic form of the same operation.
    %x = "arith.cmpi"(%lhs, %rhs) {predicate = 2 : i64} : (i32, i32) -> i1

    // Custom form of vector equality comparison.
    %x = arith.cmpi eq, %lhs, %rhs : vector<4xi64>

    // Generic form of the same operation.
    %x = "arith.cmpi"(%lhs, %rhs) {predicate = 0 : i64}
        : (vector<4xi64>, vector<4xi64>) -> vector<4xi1>
    """

    name = "arith.cmpi"
    predicate = prop_def(IntegerAttr)
    lhs = operand_def(signlessIntegerLike)
    rhs = operand_def(signlessIntegerLike)
    result = result_def(IntegerType(1))

    traits = traits_def(CmpiHasCanonicalizationPatterns(), Pure())

    def __init__(
        self,
        operand1: Operation | SSAValue,
        operand2: Operation | SSAValue,
        arg: int | str,
    ):
        operand1 = SSAValue.get(operand1)
        operand2 = SSAValue.get(operand2)
        CmpiOp._validate_operand_types(operand1, operand2)

        if isinstance(arg, str):
            cmpi_comparison_operations = {
                "eq": 0,
                "ne": 1,
                "slt": 2,
                "sle": 3,
                "sgt": 4,
                "sge": 5,
                "ult": 6,
                "ule": 7,
                "ugt": 8,
                "uge": 9,
            }
            arg = CmpiOp._get_comparison_predicate(arg, cmpi_comparison_operations)

        super().__init__(
            operands=[operand1, operand2],
            result_types=[IntegerType(1)],
            properties={"predicate": IntegerAttr(arg, 64)},
        )

    @classmethod
    def parse(cls, parser: Parser):
        arg = parser.parse_identifier()
        parser.parse_punctuation(",")
        operand1 = parser.parse_unresolved_operand()
        parser.parse_punctuation(",")
        operand2 = parser.parse_unresolved_operand()
        parser.parse_punctuation(":")
        input_type = parser.parse_type()
        (operand1, operand2) = parser.resolve_operands(
            [operand1, operand2], 2 * [input_type], parser.pos
        )

        return cls(operand1, operand2, arg)

    def print(self, printer: Printer):
        printer.print_string(" ")

        printer.print_string(CMPI_COMPARISON_OPERATIONS[self.predicate.value.data])
        printer.print_string(", ")
        printer.print_operand(self.lhs)
        printer.print_string(", ")
        printer.print_operand(self.rhs)
        printer.print_string(" : ")
        printer.print_attribute(self.lhs.type)

name = 'arith.cmpi' class-attribute instance-attribute

predicate = prop_def(IntegerAttr) class-attribute instance-attribute

lhs = operand_def(signlessIntegerLike) class-attribute instance-attribute

rhs = operand_def(signlessIntegerLike) class-attribute instance-attribute

result = result_def(IntegerType(1)) class-attribute instance-attribute

traits = traits_def(CmpiHasCanonicalizationPatterns(), Pure()) class-attribute instance-attribute

__init__(operand1: Operation | SSAValue, operand2: Operation | SSAValue, arg: int | str)

Source code in xdsl/dialects/arith.py
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
def __init__(
    self,
    operand1: Operation | SSAValue,
    operand2: Operation | SSAValue,
    arg: int | str,
):
    operand1 = SSAValue.get(operand1)
    operand2 = SSAValue.get(operand2)
    CmpiOp._validate_operand_types(operand1, operand2)

    if isinstance(arg, str):
        cmpi_comparison_operations = {
            "eq": 0,
            "ne": 1,
            "slt": 2,
            "sle": 3,
            "sgt": 4,
            "sge": 5,
            "ult": 6,
            "ule": 7,
            "ugt": 8,
            "uge": 9,
        }
        arg = CmpiOp._get_comparison_predicate(arg, cmpi_comparison_operations)

    super().__init__(
        operands=[operand1, operand2],
        result_types=[IntegerType(1)],
        properties={"predicate": IntegerAttr(arg, 64)},
    )

parse(parser: Parser) classmethod

Source code in xdsl/dialects/arith.py
889
890
891
892
893
894
895
896
897
898
899
900
901
902
@classmethod
def parse(cls, parser: Parser):
    arg = parser.parse_identifier()
    parser.parse_punctuation(",")
    operand1 = parser.parse_unresolved_operand()
    parser.parse_punctuation(",")
    operand2 = parser.parse_unresolved_operand()
    parser.parse_punctuation(":")
    input_type = parser.parse_type()
    (operand1, operand2) = parser.resolve_operands(
        [operand1, operand2], 2 * [input_type], parser.pos
    )

    return cls(operand1, operand2, arg)

print(printer: Printer)

Source code in xdsl/dialects/arith.py
904
905
906
907
908
909
910
911
912
913
def print(self, printer: Printer):
    printer.print_string(" ")

    printer.print_string(CMPI_COMPARISON_OPERATIONS[self.predicate.value.data])
    printer.print_string(", ")
    printer.print_operand(self.lhs)
    printer.print_string(", ")
    printer.print_operand(self.rhs)
    printer.print_string(" : ")
    printer.print_attribute(self.lhs.type)

CmpfOp

Bases: ComparisonOperation

The cmpf operation compares its two operands according to the float comparison rules and the predicate specified by the respective attribute. The predicate defines the type of comparison: (un)orderedness, (in)equality and signed less/greater than (or equal to) as well as predicates that are always true or false. The operands must have the same type, and this type must be a float type, or a vector or tensor thereof. The result is an i1, or a vector/tensor thereof having the same shape as the inputs. Unlike cmpi, the operands are always treated as signed. The u prefix indicates unordered comparison, not unsigned comparison, so "une" means unordered or not equal. For the sake of readability by humans, custom assembly form for the operation uses a string-typed attribute for the predicate. The value of this attribute corresponds to lower-cased name of the predicate constant, e.g., "one" means "ordered not equal". The string representation of the attribute is merely a syntactic sugar and is converted to an integer attribute by the parser.

Example:

%r1 = arith.cmpf oeq, %0, %1 : f32 %r2 = arith.cmpf ult, %0, %1 : tensor<42x42xf64> %r3 = "arith.cmpf"(%0, %1) {predicate: 0} : (f8, f8) -> i1

Source code in xdsl/dialects/arith.py
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
@irdl_op_definition
class CmpfOp(ComparisonOperation):
    """
    The cmpf operation compares its two operands according to the float
    comparison rules and the predicate specified by the respective attribute.
    The predicate defines the type of comparison: (un)orderedness, (in)equality
    and signed less/greater than (or equal to) as well as predicates that are
    always true or false.  The operands must have the same type, and this type
    must be a float type, or a vector or tensor thereof.  The result is an i1,
    or a vector/tensor thereof having the same shape as the inputs. Unlike cmpi,
    the operands are always treated as signed. The u prefix indicates
    *unordered* comparison, not unsigned comparison, so "une" means unordered or
    not equal. For the sake of readability by humans, custom assembly form for
    the operation uses a string-typed attribute for the predicate.  The value of
    this attribute corresponds to lower-cased name of the predicate constant,
    e.g., "one" means "ordered not equal".  The string representation of the
    attribute is merely a syntactic sugar and is converted to an integer
    attribute by the parser.

    Example:

    %r1 = arith.cmpf oeq, %0, %1 : f32
    %r2 = arith.cmpf ult, %0, %1 : tensor<42x42xf64>
    %r3 = "arith.cmpf"(%0, %1) {predicate: 0} : (f8, f8) -> i1
    """

    name = "arith.cmpf"
    predicate = prop_def(IntegerAttr)
    lhs = operand_def(floatingPointLike)
    rhs = operand_def(floatingPointLike)
    fastmath = prop_def(FastMathFlagsAttr, default_value=FastMathFlagsAttr("none"))
    result = result_def(IntegerType(1))

    traits = traits_def(Pure())

    def __init__(
        self,
        operand1: SSAValue | Operation,
        operand2: SSAValue | Operation,
        arg: int | str,
        fastmath: FastMathFlagsAttr = FastMathFlagsAttr("none"),
    ):
        operand1 = SSAValue.get(operand1)
        operand2 = SSAValue.get(operand2)

        CmpfOp._validate_operand_types(operand1, operand2)

        if isinstance(arg, str):
            cmpf_comparison_operations = {
                "false": 0,
                "oeq": 1,
                "ogt": 2,
                "oge": 3,
                "olt": 4,
                "ole": 5,
                "one": 6,
                "ord": 7,
                "ueq": 8,
                "ugt": 9,
                "uge": 10,
                "ult": 11,
                "ule": 12,
                "une": 13,
                "uno": 14,
                "true": 15,
            }
            arg = CmpfOp._get_comparison_predicate(arg, cmpf_comparison_operations)

        super().__init__(
            operands=[operand1, operand2],
            result_types=[IntegerType(1)],
            properties={
                "predicate": IntegerAttr(arg, 64),
                "fastmath": fastmath,
            },
        )

    @classmethod
    def parse(cls, parser: Parser):
        arg = parser.parse_identifier()
        parser.parse_punctuation(",")
        operand1 = parser.parse_unresolved_operand()
        parser.parse_punctuation(",")
        operand2 = parser.parse_unresolved_operand()
        if parser.parse_optional_keyword("fastmath"):
            fastmath = FastMathFlagsAttr(FastMathFlagsAttr.parse_parameter(parser))
        else:
            fastmath = FastMathFlagsAttr("none")
        parser.parse_punctuation(":")
        input_type = parser.parse_type()
        (operand1, operand2) = parser.resolve_operands(
            [operand1, operand2], 2 * [input_type], parser.pos
        )

        return cls(operand1, operand2, arg, fastmath)

    def print(self, printer: Printer):
        printer.print_string(" ")
        printer.print_string(CMPF_COMPARISON_OPERATIONS[self.predicate.value.data])
        printer.print_string(", ")
        printer.print_operand(self.lhs)
        printer.print_string(", ")
        printer.print_operand(self.rhs)
        if self.fastmath != FastMathFlagsAttr("none"):
            printer.print_string(" fastmath")
            self.fastmath.print_parameter(printer)
        printer.print_string(" : ")
        printer.print_attribute(self.lhs.type)

name = 'arith.cmpf' class-attribute instance-attribute

predicate = prop_def(IntegerAttr) class-attribute instance-attribute

lhs = operand_def(floatingPointLike) class-attribute instance-attribute

rhs = operand_def(floatingPointLike) class-attribute instance-attribute

fastmath = prop_def(FastMathFlagsAttr, default_value=(FastMathFlagsAttr('none'))) class-attribute instance-attribute

result = result_def(IntegerType(1)) class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

__init__(operand1: SSAValue | Operation, operand2: SSAValue | Operation, arg: int | str, fastmath: FastMathFlagsAttr = FastMathFlagsAttr('none'))

Source code in xdsl/dialects/arith.py
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
def __init__(
    self,
    operand1: SSAValue | Operation,
    operand2: SSAValue | Operation,
    arg: int | str,
    fastmath: FastMathFlagsAttr = FastMathFlagsAttr("none"),
):
    operand1 = SSAValue.get(operand1)
    operand2 = SSAValue.get(operand2)

    CmpfOp._validate_operand_types(operand1, operand2)

    if isinstance(arg, str):
        cmpf_comparison_operations = {
            "false": 0,
            "oeq": 1,
            "ogt": 2,
            "oge": 3,
            "olt": 4,
            "ole": 5,
            "one": 6,
            "ord": 7,
            "ueq": 8,
            "ugt": 9,
            "uge": 10,
            "ult": 11,
            "ule": 12,
            "une": 13,
            "uno": 14,
            "true": 15,
        }
        arg = CmpfOp._get_comparison_predicate(arg, cmpf_comparison_operations)

    super().__init__(
        operands=[operand1, operand2],
        result_types=[IntegerType(1)],
        properties={
            "predicate": IntegerAttr(arg, 64),
            "fastmath": fastmath,
        },
    )

parse(parser: Parser) classmethod

Source code in xdsl/dialects/arith.py
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
@classmethod
def parse(cls, parser: Parser):
    arg = parser.parse_identifier()
    parser.parse_punctuation(",")
    operand1 = parser.parse_unresolved_operand()
    parser.parse_punctuation(",")
    operand2 = parser.parse_unresolved_operand()
    if parser.parse_optional_keyword("fastmath"):
        fastmath = FastMathFlagsAttr(FastMathFlagsAttr.parse_parameter(parser))
    else:
        fastmath = FastMathFlagsAttr("none")
    parser.parse_punctuation(":")
    input_type = parser.parse_type()
    (operand1, operand2) = parser.resolve_operands(
        [operand1, operand2], 2 * [input_type], parser.pos
    )

    return cls(operand1, operand2, arg, fastmath)

print(printer: Printer)

Source code in xdsl/dialects/arith.py
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
def print(self, printer: Printer):
    printer.print_string(" ")
    printer.print_string(CMPF_COMPARISON_OPERATIONS[self.predicate.value.data])
    printer.print_string(", ")
    printer.print_operand(self.lhs)
    printer.print_string(", ")
    printer.print_operand(self.rhs)
    if self.fastmath != FastMathFlagsAttr("none"):
        printer.print_string(" fastmath")
        self.fastmath.print_parameter(printer)
    printer.print_string(" : ")
    printer.print_attribute(self.lhs.type)

SelectHasCanonicalizationPatterns dataclass

Bases: HasCanonicalizationPatternsTrait

Source code in xdsl/dialects/arith.py
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
class SelectHasCanonicalizationPatterns(HasCanonicalizationPatternsTrait):
    @classmethod
    def get_canonicalization_patterns(cls) -> tuple[RewritePattern, ...]:
        from xdsl.transforms.canonicalization_patterns.arith import (
            SelectConstPattern,
            SelectFoldCmpfPattern,
            SelectSamePattern,
            SelectTrueFalsePattern,
        )

        return (
            SelectConstPattern(),
            SelectTrueFalsePattern(),
            SelectSamePattern(),
            SelectFoldCmpfPattern(),
        )

get_canonicalization_patterns() -> tuple[RewritePattern, ...] classmethod

Source code in xdsl/dialects/arith.py
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
@classmethod
def get_canonicalization_patterns(cls) -> tuple[RewritePattern, ...]:
    from xdsl.transforms.canonicalization_patterns.arith import (
        SelectConstPattern,
        SelectFoldCmpfPattern,
        SelectSamePattern,
        SelectTrueFalsePattern,
    )

    return (
        SelectConstPattern(),
        SelectTrueFalsePattern(),
        SelectSamePattern(),
        SelectFoldCmpfPattern(),
    )

SelectOp

Bases: IRDLOperation

The arith.select operation chooses one value based on a binary condition supplied as its first operand. If the value of the first operand is 1, the second operand is chosen, otherwise the third operand is chosen. The second and the third operand must have the same type.

Source code in xdsl/dialects/arith.py
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
@irdl_op_definition
class SelectOp(IRDLOperation):
    """
    The `arith.select` operation chooses one value based on a binary condition
    supplied as its first operand. If the value of the first operand is `1`,
    the second operand is chosen, otherwise the third operand is chosen.
    The second and the third operand must have the same type.
    """

    name = "arith.select"

    _T: ClassVar = VarConstraint("_T", AnyAttr())
    cond = operand_def(IntegerType(1))
    lhs = operand_def(_T)
    rhs = operand_def(_T)
    result = result_def(_T)

    traits = traits_def(Pure(), SelectHasCanonicalizationPatterns())

    def __init__(
        self,
        operand1: Operation | SSAValue,
        operand2: Operation | SSAValue,
        operand3: Operation | SSAValue,
    ):
        operand2 = SSAValue.get(operand2)
        super().__init__(
            operands=[operand1, operand2, operand3], result_types=[operand2.type]
        )

    assembly_format = "$cond `,` $lhs `,` $rhs attr-dict `:` type($result)"

name = 'arith.select' class-attribute instance-attribute

cond = operand_def(IntegerType(1)) class-attribute instance-attribute

lhs = operand_def(_T) class-attribute instance-attribute

rhs = operand_def(_T) class-attribute instance-attribute

result = result_def(_T) class-attribute instance-attribute

traits = traits_def(Pure(), SelectHasCanonicalizationPatterns()) class-attribute instance-attribute

assembly_format = '$cond `,` $lhs `,` $rhs attr-dict `:` type($result)' class-attribute instance-attribute

__init__(operand1: Operation | SSAValue, operand2: Operation | SSAValue, operand3: Operation | SSAValue)

Source code in xdsl/dialects/arith.py
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
def __init__(
    self,
    operand1: Operation | SSAValue,
    operand2: Operation | SSAValue,
    operand3: Operation | SSAValue,
):
    operand2 = SSAValue.get(operand2)
    super().__init__(
        operands=[operand1, operand2, operand3], result_types=[operand2.type]
    )

AddfOp dataclass

Bases: FloatingPointLikeBinaryOperation

Source code in xdsl/dialects/arith.py
1077
1078
1079
1080
1081
1082
1083
1084
@irdl_op_definition
class AddfOp(FloatingPointLikeBinaryOperation):
    name = "arith.addf"

    traits = traits_def(
        Pure(),
        FloatingPointLikeBinaryOpHasFastReassociativeCanonicalizationPatternsTrait(),
    )

name = 'arith.addf' class-attribute instance-attribute

traits = traits_def(Pure(), FloatingPointLikeBinaryOpHasFastReassociativeCanonicalizationPatternsTrait()) class-attribute instance-attribute

SubfOp dataclass

Bases: FloatingPointLikeBinaryOperation

Source code in xdsl/dialects/arith.py
1087
1088
1089
1090
1091
1092
1093
@irdl_op_definition
class SubfOp(FloatingPointLikeBinaryOperation):
    name = "arith.subf"

    traits = traits_def(
        Pure(), FloatingPointLikeBinaryOpHasCanonicalizationPatternsTrait()
    )

name = 'arith.subf' class-attribute instance-attribute

traits = traits_def(Pure(), FloatingPointLikeBinaryOpHasCanonicalizationPatternsTrait()) class-attribute instance-attribute

MulfOp dataclass

Bases: FloatingPointLikeBinaryOperation

Source code in xdsl/dialects/arith.py
1096
1097
1098
1099
1100
1101
1102
1103
@irdl_op_definition
class MulfOp(FloatingPointLikeBinaryOperation):
    name = "arith.mulf"

    traits = traits_def(
        Pure(),
        FloatingPointLikeBinaryOpHasFastReassociativeCanonicalizationPatternsTrait(),
    )

name = 'arith.mulf' class-attribute instance-attribute

traits = traits_def(Pure(), FloatingPointLikeBinaryOpHasFastReassociativeCanonicalizationPatternsTrait()) class-attribute instance-attribute

DivfOp dataclass

Bases: FloatingPointLikeBinaryOperation

Source code in xdsl/dialects/arith.py
1106
1107
1108
1109
1110
1111
1112
@irdl_op_definition
class DivfOp(FloatingPointLikeBinaryOperation):
    name = "arith.divf"

    traits = traits_def(
        Pure(), FloatingPointLikeBinaryOpHasCanonicalizationPatternsTrait()
    )

name = 'arith.divf' class-attribute instance-attribute

traits = traits_def(Pure(), FloatingPointLikeBinaryOpHasCanonicalizationPatternsTrait()) class-attribute instance-attribute

NegfOp

Bases: IRDLOperation

Source code in xdsl/dialects/arith.py
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
@irdl_op_definition
class NegfOp(IRDLOperation):
    name = "arith.negf"

    _T: ClassVar = VarConstraint("_T", floatingPointLike)

    fastmath = prop_def(FastMathFlagsAttr, default_value=FastMathFlagsAttr("none"))
    operand = operand_def(_T)
    result = result_def(_T)

    traits = traits_def(Pure())

    def __init__(
        self, operand: Operation | SSAValue, fastmath: FastMathFlagsAttr | None = None
    ):
        operand = SSAValue.get(operand)
        super().__init__(
            attributes={"fastmath": fastmath},
            operands=[operand],
            result_types=[operand.type],
        )

    assembly_format = "$operand (`fastmath` `` $fastmath^)? attr-dict `:` type($result)"

name = 'arith.negf' class-attribute instance-attribute

fastmath = prop_def(FastMathFlagsAttr, default_value=(FastMathFlagsAttr('none'))) class-attribute instance-attribute

operand = operand_def(_T) class-attribute instance-attribute

result = result_def(_T) class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

assembly_format = '$operand (`fastmath` `` $fastmath^)? attr-dict `:` type($result)' class-attribute instance-attribute

__init__(operand: Operation | SSAValue, fastmath: FastMathFlagsAttr | None = None)

Source code in xdsl/dialects/arith.py
1127
1128
1129
1130
1131
1132
1133
1134
1135
def __init__(
    self, operand: Operation | SSAValue, fastmath: FastMathFlagsAttr | None = None
):
    operand = SSAValue.get(operand)
    super().__init__(
        attributes={"fastmath": fastmath},
        operands=[operand],
        result_types=[operand.type],
    )

MaximumfOp dataclass

Bases: FloatingPointLikeBinaryOperation

Returns the maximum of the two arguments, treating -0.0 as less than +0.0. If one of the arguments is NaN, then the result is also NaN.

Source code in xdsl/dialects/arith.py
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
@irdl_op_definition
class MaximumfOp(FloatingPointLikeBinaryOperation):
    """
    Returns the maximum of the two arguments, treating -0.0 as less than +0.0.
    If one of the arguments is NaN, then the result is also NaN.
    """

    name = "arith.maximumf"

    traits = traits_def(Pure())

name = 'arith.maximumf' class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

MaxnumfOp dataclass

Bases: FloatingPointLikeBinaryOperation

Returns the maximum of the two arguments. If the arguments are -0.0 and +0.0, then the result is either of them. If one of the arguments is NaN, then the result is the other argument.

Source code in xdsl/dialects/arith.py
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
@irdl_op_definition
class MaxnumfOp(FloatingPointLikeBinaryOperation):
    """
    Returns the maximum of the two arguments.
    If the arguments are -0.0 and +0.0, then the result is either of them.
    If one of the arguments is NaN, then the result is the other argument.
    """

    name = "arith.maxnumf"

    traits = traits_def(Pure())

name = 'arith.maxnumf' class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

MinimumfOp dataclass

Bases: FloatingPointLikeBinaryOperation

Returns the minimum of the two arguments, treating -0.0 as less than +0.0. If one of the arguments is NaN, then the result is also NaN.

Source code in xdsl/dialects/arith.py
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
@irdl_op_definition
class MinimumfOp(FloatingPointLikeBinaryOperation):
    """
    Returns the minimum of the two arguments, treating -0.0 as less than +0.0.
    If one of the arguments is NaN, then the result is also NaN.
    """

    name = "arith.minimumf"

    traits = traits_def(Pure())

name = 'arith.minimumf' class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

MinnumfOp dataclass

Bases: FloatingPointLikeBinaryOperation

Returns the minimum of the two arguments. If the arguments are -0.0 and +0.0, then the result is either of them. If one of the arguments is NaN, then the result is the other argument.

Source code in xdsl/dialects/arith.py
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
@irdl_op_definition
class MinnumfOp(FloatingPointLikeBinaryOperation):
    """
    Returns the minimum of the two arguments. If the arguments are -0.0 and +0.0, then the result is either of them.
    If one of the arguments is NaN, then the result is the other argument.
    """

    name = "arith.minnumf"

    traits = traits_def(Pure())

name = 'arith.minnumf' class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

BitcastOp

Bases: IRDLOperation

Source code in xdsl/dialects/arith.py
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
@irdl_op_definition
class BitcastOp(IRDLOperation):
    name = "arith.bitcast"

    input = operand_def(
        ContainerOf(AnyOf((IntegerType, IndexType)) | AnyFloatConstr)
        | MemRefType.constr(element_type=AnyFloatConstr | SignlessIntegerConstraint)
    )
    result = result_def(
        ContainerOf(AnyOf((IntegerType, IndexType)) | AnyFloatConstr)
        | MemRefType.constr(element_type=AnyFloatConstr | SignlessIntegerConstraint)
    )

    traits = traits_def(Pure())

    assembly_format = "$input attr-dict `:` type($input) `to` type($result)"

    def __init__(self, in_arg: SSAValue | Operation, target_type: Attribute):
        super().__init__(operands=[in_arg], result_types=[target_type])

    def verify_(self) -> None:
        in_type = self.input.type
        res_type = self.result.type

        if not have_compatible_shape(in_type, res_type):
            raise VerifyException("operand and result type must have compatible shape")

        t1 = get_element_type_or_self(in_type)
        t2 = get_element_type_or_self(res_type)
        if not BitcastOp._are_types_bitcastable(t1, t2):
            raise VerifyException(
                "operand and result types must have equal bitwidths or be IndexType"
            )

    @staticmethod
    def _are_types_bitcastable(type_a: Attribute, type_b: Attribute) -> bool:
        if isinstance(type_a, IndexType) or isinstance(type_b, IndexType):
            return True

        if isinstance(type_a, FixedBitwidthType) and isinstance(
            type_b, FixedBitwidthType
        ):
            return type_a.bitwidth == type_b.bitwidth

        return False

name = 'arith.bitcast' class-attribute instance-attribute

input = operand_def(ContainerOf(AnyOf((IntegerType, IndexType)) | AnyFloatConstr) | MemRefType.constr(element_type=(AnyFloatConstr | SignlessIntegerConstraint))) class-attribute instance-attribute

result = result_def(ContainerOf(AnyOf((IntegerType, IndexType)) | AnyFloatConstr) | MemRefType.constr(element_type=(AnyFloatConstr | SignlessIntegerConstraint))) class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

assembly_format = '$input attr-dict `:` type($input) `to` type($result)' class-attribute instance-attribute

__init__(in_arg: SSAValue | Operation, target_type: Attribute)

Source code in xdsl/dialects/arith.py
1206
1207
def __init__(self, in_arg: SSAValue | Operation, target_type: Attribute):
    super().__init__(operands=[in_arg], result_types=[target_type])

verify_() -> None

Source code in xdsl/dialects/arith.py
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
def verify_(self) -> None:
    in_type = self.input.type
    res_type = self.result.type

    if not have_compatible_shape(in_type, res_type):
        raise VerifyException("operand and result type must have compatible shape")

    t1 = get_element_type_or_self(in_type)
    t2 = get_element_type_or_self(res_type)
    if not BitcastOp._are_types_bitcastable(t1, t2):
        raise VerifyException(
            "operand and result types must have equal bitwidths or be IndexType"
        )

IndexCastOp

Bases: IRDLOperation

Source code in xdsl/dialects/arith.py
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
@irdl_op_definition
class IndexCastOp(IRDLOperation):
    name = "arith.index_cast"

    input = operand_def(base(IntegerType) | base(IndexType))

    result = result_def(base(IntegerType) | base(IndexType))

    traits = traits_def(Pure())

    assembly_format = "$input attr-dict `:` type($input) `to` type($result)"

    def __init__(self, input_arg: SSAValue | Operation, target_type: Attribute):
        super().__init__(operands=[input_arg], result_types=[target_type])

    def verify_(self) -> None:
        it = IndexType
        # exactly one of input or result must be of IndexType, no more, no less.
        if not isinstance(self.input.type, it) ^ isinstance(self.result.type, it):
            raise VerifyException(
                f"'arith.index_cast' op operand type '{self.input.type}' and result "
                f"type '{self.input.type}' are cast incompatible"
            )

name = 'arith.index_cast' class-attribute instance-attribute

input = operand_def(base(IntegerType) | base(IndexType)) class-attribute instance-attribute

result = result_def(base(IntegerType) | base(IndexType)) class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

assembly_format = '$input attr-dict `:` type($input) `to` type($result)' class-attribute instance-attribute

__init__(input_arg: SSAValue | Operation, target_type: Attribute)

Source code in xdsl/dialects/arith.py
1248
1249
def __init__(self, input_arg: SSAValue | Operation, target_type: Attribute):
    super().__init__(operands=[input_arg], result_types=[target_type])

verify_() -> None

Source code in xdsl/dialects/arith.py
1251
1252
1253
1254
1255
1256
1257
1258
def verify_(self) -> None:
    it = IndexType
    # exactly one of input or result must be of IndexType, no more, no less.
    if not isinstance(self.input.type, it) ^ isinstance(self.result.type, it):
        raise VerifyException(
            f"'arith.index_cast' op operand type '{self.input.type}' and result "
            f"type '{self.input.type}' are cast incompatible"
        )

FloatingPointToIntegerBaseOp

Bases: IRDLOperation, ABC

Source code in xdsl/dialects/arith.py
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
class FloatingPointToIntegerBaseOp(IRDLOperation, abc.ABC):
    input = operand_def(AnyFloatConstr)
    result = result_def(IntegerType)

    assembly_format = "$input attr-dict `:` type($input) `to` type($result)"

    traits = traits_def(Pure())

    def __init__(self, op: SSAValue | Operation, target_type: IntegerType):
        super().__init__(operands=[op], result_types=[target_type])

input = operand_def(AnyFloatConstr) class-attribute instance-attribute

result = result_def(IntegerType) class-attribute instance-attribute

assembly_format = '$input attr-dict `:` type($input) `to` type($result)' class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

__init__(op: SSAValue | Operation, target_type: IntegerType)

Source code in xdsl/dialects/arith.py
1269
1270
def __init__(self, op: SSAValue | Operation, target_type: IntegerType):
    super().__init__(operands=[op], result_types=[target_type])

FPToSIOp dataclass

Bases: FloatingPointToIntegerBaseOp

Source code in xdsl/dialects/arith.py
1273
1274
1275
@irdl_op_definition
class FPToSIOp(FloatingPointToIntegerBaseOp):
    name = "arith.fptosi"

name = 'arith.fptosi' class-attribute instance-attribute

FPToUIOp dataclass

Bases: FloatingPointToIntegerBaseOp

Source code in xdsl/dialects/arith.py
1278
1279
1280
@irdl_op_definition
class FPToUIOp(FloatingPointToIntegerBaseOp):
    name = "arith.fptoui"

name = 'arith.fptoui' class-attribute instance-attribute

IntegerToFloatingPointBaseOp

Bases: IRDLOperation, ABC

Source code in xdsl/dialects/arith.py
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
class IntegerToFloatingPointBaseOp(IRDLOperation, abc.ABC):
    input = operand_def(IntegerType)
    result = result_def(AnyFloatConstr)

    assembly_format = "$input attr-dict `:` type($input) `to` type($result)"

    traits = traits_def(Pure())

    def __init__(self, op: SSAValue | Operation, target_type: AnyFloat):
        super().__init__(operands=[op], result_types=[target_type])

input = operand_def(IntegerType) class-attribute instance-attribute

result = result_def(AnyFloatConstr) class-attribute instance-attribute

assembly_format = '$input attr-dict `:` type($input) `to` type($result)' class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

__init__(op: SSAValue | Operation, target_type: AnyFloat)

Source code in xdsl/dialects/arith.py
1291
1292
def __init__(self, op: SSAValue | Operation, target_type: AnyFloat):
    super().__init__(operands=[op], result_types=[target_type])

SIToFPOp dataclass

Bases: IntegerToFloatingPointBaseOp

Source code in xdsl/dialects/arith.py
1295
1296
1297
@irdl_op_definition
class SIToFPOp(IntegerToFloatingPointBaseOp):
    name = "arith.sitofp"

name = 'arith.sitofp' class-attribute instance-attribute

UIToFPOp dataclass

Bases: IntegerToFloatingPointBaseOp

Source code in xdsl/dialects/arith.py
1300
1301
1302
@irdl_op_definition
class UIToFPOp(IntegerToFloatingPointBaseOp):
    name = "arith.uitofp"

name = 'arith.uitofp' class-attribute instance-attribute

ExtFOp

Bases: IRDLOperation

Source code in xdsl/dialects/arith.py
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
@irdl_op_definition
class ExtFOp(IRDLOperation):
    name = "arith.extf"

    input = operand_def(AnyFloatConstr)
    result = result_def(AnyFloatConstr)

    def __init__(self, op: SSAValue | Operation, target_type: AnyFloat):
        super().__init__(operands=[op], result_types=[target_type])

    assembly_format = "$input attr-dict `:` type($input) `to` type($result)"

    traits = traits_def(Pure())

name = 'arith.extf' class-attribute instance-attribute

input = operand_def(AnyFloatConstr) class-attribute instance-attribute

result = result_def(AnyFloatConstr) class-attribute instance-attribute

assembly_format = '$input attr-dict `:` type($input) `to` type($result)' class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

__init__(op: SSAValue | Operation, target_type: AnyFloat)

Source code in xdsl/dialects/arith.py
1312
1313
def __init__(self, op: SSAValue | Operation, target_type: AnyFloat):
    super().__init__(operands=[op], result_types=[target_type])

TruncFOp

Bases: IRDLOperation

Source code in xdsl/dialects/arith.py
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
@irdl_op_definition
class TruncFOp(IRDLOperation):
    name = "arith.truncf"

    input = operand_def(AnyFloatConstr)
    result = result_def(AnyFloatConstr)

    def __init__(self, op: SSAValue | Operation, target_type: AnyFloat):
        super().__init__(operands=[op], result_types=[target_type])

    assembly_format = "$input attr-dict `:` type($input) `to` type($result)"

    traits = traits_def(Pure())

name = 'arith.truncf' class-attribute instance-attribute

input = operand_def(AnyFloatConstr) class-attribute instance-attribute

result = result_def(AnyFloatConstr) class-attribute instance-attribute

assembly_format = '$input attr-dict `:` type($input) `to` type($result)' class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

__init__(op: SSAValue | Operation, target_type: AnyFloat)

Source code in xdsl/dialects/arith.py
1327
1328
def __init__(self, op: SSAValue | Operation, target_type: AnyFloat):
    super().__init__(operands=[op], result_types=[target_type])

TruncIOp

Bases: IRDLOperation

Source code in xdsl/dialects/arith.py
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
@irdl_op_definition
class TruncIOp(IRDLOperation):
    name = "arith.trunci"

    input = operand_def(IntegerType)
    result = result_def(IntegerType)

    def __init__(self, op: SSAValue | Operation, target_type: IntegerType):
        super().__init__(operands=[op], result_types=[target_type])

    def verify_(self) -> None:
        assert isa(self.input.type, IntegerType)
        if not self.result.type.width.data < self.input.type.width.data:
            raise VerifyException(
                "Destination bit-width must be smaller than the input bit-width"
            )

    assembly_format = "$input attr-dict `:` type($input) `to` type($result)"

    traits = traits_def(Pure())

name = 'arith.trunci' class-attribute instance-attribute

input = operand_def(IntegerType) class-attribute instance-attribute

result = result_def(IntegerType) class-attribute instance-attribute

assembly_format = '$input attr-dict `:` type($input) `to` type($result)' class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

__init__(op: SSAValue | Operation, target_type: IntegerType)

Source code in xdsl/dialects/arith.py
1342
1343
def __init__(self, op: SSAValue | Operation, target_type: IntegerType):
    super().__init__(operands=[op], result_types=[target_type])

verify_() -> None

Source code in xdsl/dialects/arith.py
1345
1346
1347
1348
1349
1350
def verify_(self) -> None:
    assert isa(self.input.type, IntegerType)
    if not self.result.type.width.data < self.input.type.width.data:
        raise VerifyException(
            "Destination bit-width must be smaller than the input bit-width"
        )

ExtSIOp

Bases: IRDLOperation

Source code in xdsl/dialects/arith.py
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
@irdl_op_definition
class ExtSIOp(IRDLOperation):
    name = "arith.extsi"

    input = operand_def(IntegerType)
    result = result_def(IntegerType)

    def __init__(self, op: SSAValue | Operation, target_type: IntegerType):
        super().__init__(operands=[op], result_types=[target_type])

    def verify_(self) -> None:
        assert isa(self.input.type, IntegerType)
        if not self.result.type.width.data > self.input.type.width.data:
            raise VerifyException(
                "Destination bit-width must be larger than the input bit-width"
            )

    assembly_format = "$input attr-dict `:` type($input) `to` type($result)"

name = 'arith.extsi' class-attribute instance-attribute

input = operand_def(IntegerType) class-attribute instance-attribute

result = result_def(IntegerType) class-attribute instance-attribute

assembly_format = '$input attr-dict `:` type($input) `to` type($result)' class-attribute instance-attribute

__init__(op: SSAValue | Operation, target_type: IntegerType)

Source code in xdsl/dialects/arith.py
1364
1365
def __init__(self, op: SSAValue | Operation, target_type: IntegerType):
    super().__init__(operands=[op], result_types=[target_type])

verify_() -> None

Source code in xdsl/dialects/arith.py
1367
1368
1369
1370
1371
1372
def verify_(self) -> None:
    assert isa(self.input.type, IntegerType)
    if not self.result.type.width.data > self.input.type.width.data:
        raise VerifyException(
            "Destination bit-width must be larger than the input bit-width"
        )

ExtUIOp

Bases: IRDLOperation

Source code in xdsl/dialects/arith.py
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
@irdl_op_definition
class ExtUIOp(IRDLOperation):
    name = "arith.extui"

    input = operand_def(IntegerType)
    result = result_def(IntegerType)

    def __init__(self, op: SSAValue | Operation, target_type: IntegerType):
        super().__init__(operands=[op], result_types=[target_type])

    def verify_(self) -> None:
        assert isa(self.input.type, IntegerType)
        if not self.result.type.width.data > self.input.type.width.data:
            raise VerifyException(
                "Destination bit-width must be larger than the input bit-width"
            )

    assembly_format = "$input attr-dict `:` type($input) `to` type($result)"

    traits = traits_def(Pure())

name = 'arith.extui' class-attribute instance-attribute

input = operand_def(IntegerType) class-attribute instance-attribute

result = result_def(IntegerType) class-attribute instance-attribute

assembly_format = '$input attr-dict `:` type($input) `to` type($result)' class-attribute instance-attribute

traits = traits_def(Pure()) class-attribute instance-attribute

__init__(op: SSAValue | Operation, target_type: IntegerType)

Source code in xdsl/dialects/arith.py
1384
1385
def __init__(self, op: SSAValue | Operation, target_type: IntegerType):
    super().__init__(operands=[op], result_types=[target_type])

verify_() -> None

Source code in xdsl/dialects/arith.py
1387
1388
1389
1390
1391
1392
def verify_(self) -> None:
    assert isa(self.input.type, IntegerType)
    if not self.result.type.width.data > self.input.type.width.data:
        raise VerifyException(
            "Destination bit-width must be larger than the input bit-width"
        )

ArithConstantMaterializationInterface

Bases: ConstantMaterializationInterface

Source code in xdsl/dialects/arith.py
1399
1400
1401
1402
1403
1404
class ArithConstantMaterializationInterface(ConstantMaterializationInterface):
    def materialize_constant(self, value: Attribute, type: Attribute) -> Operation:
        return cast(
            Operation,
            ConstantOp.build(properties={"value": value}, result_types=(type,)),
        )

materialize_constant(value: Attribute, type: Attribute) -> Operation

Source code in xdsl/dialects/arith.py
1400
1401
1402
1403
1404
def materialize_constant(self, value: Attribute, type: Attribute) -> Operation:
    return cast(
        Operation,
        ConstantOp.build(properties={"value": value}, result_types=(type,)),
    )