Skip to content

Commit

Permalink
misc: remove redundant AnyAttr() constraints from op definitions [N…
Browse files Browse the repository at this point in the history
…FC] (#3181)
  • Loading branch information
superlopuh authored Sep 17, 2024
1 parent 7d0a295 commit b1b8e79
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 37 deletions.
5 changes: 2 additions & 3 deletions docs/Toy/toy/dialects/toy.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
)
from xdsl.ir import Attribute, Block, Dialect, Operation, OpResult, Region, SSAValue
from xdsl.irdl import (
AnyAttr,
IRDLOperation,
attr_def,
base,
Expand Down Expand Up @@ -265,7 +264,7 @@ def verify_(self):
@irdl_op_definition
class GenericCallOp(IRDLOperation):
name = "toy.generic_call"
arguments = var_operand_def(AnyAttr())
arguments = var_operand_def()
callee = attr_def(SymbolRefAttr)

# Note: naming this results triggers an ArgumentError
Expand Down Expand Up @@ -351,7 +350,7 @@ class PrintOp(IRDLOperation):
"""

name = "toy.print"
input = operand_def(AnyAttr())
input = operand_def()

def __init__(self, input: SSAValue):
return super().__init__(operands=[input])
Expand Down
5 changes: 2 additions & 3 deletions tests/test_parser_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from xdsl.context import MLContext
from xdsl.irdl import (
AnyAttr,
IRDLOperation,
irdl_op_definition,
var_operand_def,
Expand All @@ -15,8 +14,8 @@
@irdl_op_definition
class UnknownOp(IRDLOperation):
name = "test.unknown"
ops = var_operand_def(AnyAttr())
res = var_result_def(AnyAttr())
ops = var_operand_def()
res = var_result_def()


def check_error(prog: str, line: int, column: int, message: str):
Expand Down
5 changes: 2 additions & 3 deletions xdsl/dialects/affine.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
from xdsl.ir import Attribute, Block, Dialect, Operation, Region, SSAValue
from xdsl.ir.affine import AffineExpr, AffineMap
from xdsl.irdl import (
AnyAttr,
AttrSizedOperandSegments,
ConstraintVar,
IRDLOperation,
Expand Down Expand Up @@ -116,7 +115,7 @@ class For(IRDLOperation):
lowerBoundOperands = var_operand_def(IndexType)
upperBoundOperands = var_operand_def(IndexType)
inits = var_operand_def()
res = var_result_def(AnyAttr())
res = var_result_def()

lowerBoundMap = prop_def(AffineMapAttr)
upperBoundMap = prop_def(AffineMapAttr)
Expand Down Expand Up @@ -353,7 +352,7 @@ def verify_(self) -> None:
@irdl_op_definition
class Yield(IRDLOperation):
name = "affine.yield"
arguments = var_operand_def(AnyAttr())
arguments = var_operand_def()

traits = frozenset([IsTerminator(), Pure()])

Expand Down
3 changes: 1 addition & 2 deletions xdsl/dialects/experimental/aie.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from xdsl.dialects import memref
from xdsl.dialects.builtin import (
I32,
AnyAttr,
AnyIntegerAttr,
ArrayAttr,
Block,
Expand Down Expand Up @@ -611,7 +610,7 @@ def parse(cls, parser: Parser) -> DMAStartOp:
@irdl_op_definition
class DebugOp(IRDLOperation):
name = "aie.debug"
arg = operand_def(AnyAttr())
arg = operand_def()

def __init__(self, arg: Operation | SSAValue):
super().__init__(operands=[arg])
Expand Down
14 changes: 6 additions & 8 deletions xdsl/dialects/experimental/air.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
TypeAttribute,
)
from xdsl.irdl import (
AnyAttr,
AttrSizedOperandSegments,
IRDLOperation,
ParsePropInAttrDict,
Expand Down Expand Up @@ -333,9 +332,8 @@ def parse(cls, parser: Parser) -> ExecuteOp:
class ExecuteTerminatorOp(IRDLOperation):
name = "air.execute_terminator"

results_op = var_operand_def(
AnyAttr()
) # even though this is an operand they decided to name it "result" in the original specification
# even though this is an operand they decided to name it "result" in the original specification
results_op = var_operand_def()

traits = frozenset([HasParent(ExecuteOp), IsTerminator()])

Expand Down Expand Up @@ -369,7 +367,7 @@ class HerdOp(IRDLOperation):
sym_name = opt_prop_def(StringAttr)
async_dependencies = var_operand_def(AsyncTokenAttr())
sizes = var_operand_def(IndexType())
herd_operands = var_operand_def(AnyAttr())
herd_operands = var_operand_def()
async_token = opt_result_def(AsyncTokenAttr)
region = opt_region_def()

Expand Down Expand Up @@ -517,7 +515,7 @@ class LaunchOp(IRDLOperation):
sym_name = opt_prop_def(StringAttr)
async_dependencies = var_operand_def(AsyncTokenAttr())
sizes = var_operand_def(IndexType())
launch_operands = var_operand_def(AnyAttr())
launch_operands = var_operand_def()
async_token = result_def(AsyncTokenAttr)
body = opt_region_def()

Expand Down Expand Up @@ -674,7 +672,7 @@ class PipelineStageOp(IRDLOperation):
name = "air.pipeline.stage"

opers = var_operand_def(Attribute)
result = var_result_def(AnyAttr())
result = var_result_def()

body = opt_region_def()

Expand Down Expand Up @@ -751,7 +749,7 @@ class SegmentOp(IRDLOperation):
sym_name = opt_prop_def(StringAttr)
async_dependencies = var_operand_def(AsyncTokenAttr())
sizes = var_operand_def(IndexType())
segment_operands = var_operand_def(AnyAttr())
segment_operands = var_operand_def()
async_token = result_def(AsyncTokenAttr)

body = opt_region_def()
Expand Down
7 changes: 3 additions & 4 deletions xdsl/dialects/experimental/hls.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
)
from xdsl.ir import Dialect, Operation, Region, SSAValue, TypeAttribute
from xdsl.irdl import (
AnyAttr,
IRDLOperation,
ParameterDef,
attr_def,
Expand All @@ -27,7 +26,7 @@
@irdl_op_definition
class HLSYield(IRDLOperation):
name = "hls.yield"
arguments = var_operand_def(AnyAttr())
arguments = var_operand_def()

traits = frozenset([IsTerminator()])

Expand Down Expand Up @@ -115,7 +114,7 @@ def get(elem_type: Attribute) -> HLSStream:
@irdl_op_definition
class HLSStreamWrite(IRDLOperation):
name = "hls.write"
element = operand_def(AnyAttr())
element = operand_def()
stream = operand_def(HLSStreamType)

def __init__(self, element: SSAValue | Operation, stream: SSAValue | Operation):
Expand All @@ -126,7 +125,7 @@ def __init__(self, element: SSAValue | Operation, stream: SSAValue | Operation):
class HLSStreamRead(IRDLOperation):
name = "hls.read"
stream = operand_def(HLSStreamType)
res = result_def(AnyAttr())
res = result_def()

def __init__(self, stream: SSAValue):
assert isinstance(stream.type, HLSStreamType)
Expand Down
11 changes: 5 additions & 6 deletions xdsl/dialects/fsm.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
TypeAttribute,
)
from xdsl.irdl import (
AnyAttr,
IRDLOperation,
attr_def,
irdl_attr_definition,
Expand Down Expand Up @@ -186,7 +185,7 @@ class OutputOp(IRDLOperation):

name = "fsm.output"

operand = var_operand_def(AnyAttr())
operand = var_operand_def()

traits = frozenset([IsTerminator(), HasParent(StateOp)])

Expand Down Expand Up @@ -412,11 +411,11 @@ class TriggerOp(IRDLOperation):

name = "fsm.trigger"

inputs = var_operand_def(AnyAttr())
inputs = var_operand_def()

instance = operand_def(InstanceType)

outputs = var_result_def(AnyAttr())
outputs = var_result_def()

def __init__(
self,
Expand Down Expand Up @@ -464,11 +463,11 @@ class HWInstanceOp(IRDLOperation):

sym_name = attr_def(StringAttr)
machine = attr_def(FlatSymbolRefAttrConstr)
inputs = var_operand_def(AnyAttr())
inputs = var_operand_def()
clock = operand_def(signlessIntegerLike)
reset = operand_def(signlessIntegerLike)

outputs = var_result_def(AnyAttr())
outputs = var_result_def()

def __init__(
self,
Expand Down
3 changes: 1 addition & 2 deletions xdsl/dialects/hw.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
TypeAttribute,
)
from xdsl.irdl import (
AnyAttr,
IRDLOperation,
SingleBlockRegion,
attr_def,
Expand Down Expand Up @@ -1243,7 +1242,7 @@ def print_output_port(name: str, port_type: Attribute):
class OutputOp(IRDLOperation):
name = "hw.output"

inputs = var_operand_def(AnyAttr())
inputs = var_operand_def()

traits = frozenset([IsTerminator(), HasParent(HWModuleOp)])

Expand Down
5 changes: 2 additions & 3 deletions xdsl/dialects/vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
)
from xdsl.ir import Attribute, Dialect, Operation, SSAValue
from xdsl.irdl import (
AnyAttr,
IRDLOperation,
irdl_op_definition,
operand_def,
Expand Down Expand Up @@ -86,7 +85,7 @@ def get(
@irdl_op_definition
class Broadcast(IRDLOperation):
name = "vector.broadcast"
source = operand_def(AnyAttr())
source = operand_def()
vector = result_def(VectorType)
traits = frozenset((Pure(),))

Expand Down Expand Up @@ -262,7 +261,7 @@ def get(
@irdl_op_definition
class Print(IRDLOperation):
name = "vector.print"
source = operand_def(AnyAttr())
source = operand_def()

@staticmethod
def get(source: Operation | SSAValue) -> Print:
Expand Down
5 changes: 2 additions & 3 deletions xdsl/frontend/symref.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from xdsl.dialects.builtin import StringAttr, SymbolRefAttr
from xdsl.ir import Attribute, Dialect, Operation, SSAValue
from xdsl.irdl import (
AnyAttr,
IRDLOperation,
attr_def,
irdl_op_definition,
Expand All @@ -27,7 +26,7 @@ def get(sym_name: str | StringAttr) -> Declare:
@irdl_op_definition
class Fetch(IRDLOperation):
name = "symref.fetch"
value = result_def(AnyAttr())
value = result_def()
symbol = attr_def(SymbolRefAttr)

@staticmethod
Expand All @@ -40,7 +39,7 @@ def get(symbol: str | SymbolRefAttr, result_type: Attribute) -> Fetch:
@irdl_op_definition
class Update(IRDLOperation):
name = "symref.update"
value = operand_def(AnyAttr())
value = operand_def()
symbol = attr_def(SymbolRefAttr)

@staticmethod
Expand Down

0 comments on commit b1b8e79

Please sign in to comment.