Skip to content

Commit

Permalink
dialects: (mod_arith) Add updates based on review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
emmau678 authored and emmau678 committed Oct 8, 2024
1 parent 97f2b00 commit c928b3c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
2 changes: 1 addition & 1 deletion tests/filecheck/dialects/mod_arith/mod_arith.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
%lhsi1, %rhsi1 = "test.op"() : () -> (i1, i1)

// CHECK: %add_res = mod_arith.add %lhsi1, %rhsi1 {"modulus" = 17 : i64} : i1
// CHECK-GENERIC: %add_res = "mod_arith.add"(%lhsi1, %rhsi1) {"modulus" = 17 : i64} : (i1, i1) -> i1
// CHECK-GENERIC: %add_res = "mod_arith.add"(%lhsi1, %rhsi1) <{"modulus" = 17 : i64}> : (i1, i1) -> i1
%add_res = "mod_arith.add"(%lhsi1, %rhsi1) {modulus=17} : (i1, i1) -> i1
20 changes: 9 additions & 11 deletions xdsl/dialects/mod_arith.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
from xdsl.irdl import (
ConstraintVar,
IRDLOperation,
attr_def,
ParsePropInAttrDict,
irdl_op_definition,
operand_def,
prop_def,
result_def,
)
from xdsl.traits import Pure
Expand All @@ -33,10 +34,13 @@ class BinaryOp(ModArithOp, ABC, Generic[_T]):
"""

T = Annotated[Attribute, ConstraintVar("T"), _T]
modulus = prop_def(AnyIntegerAttr)
lhs = operand_def(T)
rhs = operand_def(T)
output = result_def(T)

irdl_options = [ParsePropInAttrDict()]

assembly_format = "$lhs `,` $rhs attr-dict `:` type($output)"
traits = frozenset((Pure(),))

Expand All @@ -52,20 +56,14 @@ def __init__(
super().__init__(operands=[lhs, rhs], result_types=[result_type])


class BinaryModuloOp(BinaryOp[_T], ABC, Generic[_T]):
"""
Adds the modulus attribute
"""

modulus = attr_def(AnyIntegerAttr)


@irdl_op_definition
class AddOp(BinaryModuloOp[Annotated[Attribute, signlessIntegerLike]]):
class AddOp(BinaryOp[Annotated[Attribute, signlessIntegerLike]]):
name = "mod_arith.add"


ModArith = Dialect(
"mod_arith",
[AddOp],
[
AddOp,
],
)

0 comments on commit c928b3c

Please sign in to comment.