Skip to content

Commit 52a5eaa

Browse files
committed
dialects (riscv): make fastmath a property (and set it in all cases)
1 parent 4c18a73 commit 52a5eaa

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

xdsl/dialects/riscv.py

+16-11
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
irdl_op_definition,
4444
operand_def,
4545
opt_attr_def,
46+
opt_prop_def,
4647
region_def,
4748
result_def,
4849
var_operand_def,
@@ -2491,7 +2492,7 @@ class LiOp(RISCVInstruction, ABC):
24912492

24922493
rd = result_def(IntRegisterType)
24932494
immediate = attr_def(base(Imm32Attr) | base(LabelAttr))
2494-
fastmath = opt_attr_def(FastMathFlagsAttr)
2495+
fastmath = opt_prop_def(FastMathFlagsAttr)
24952496

24962497
traits = frozenset((Pure(), ConstantLike(), LiOpHasCanonicalizationPatternTrait()))
24972498

@@ -2500,7 +2501,7 @@ def __init__(
25002501
immediate: int | Imm32Attr | str | LabelAttr,
25012502
*,
25022503
rd: IntRegisterType | str | None = None,
2503-
fastmath: FastMathFlagsAttr | None = None,
2504+
fastmath: FastMathFlagsAttr = FastMathFlagsAttr("none"),
25042505
comment: str | StringAttr | None = None,
25052506
):
25062507
if isinstance(immediate, int):
@@ -2516,10 +2517,12 @@ def __init__(
25162517

25172518
super().__init__(
25182519
result_types=[rd],
2520+
properties={
2521+
"fastmath": fastmath,
2522+
},
25192523
attributes={
25202524
"immediate": immediate,
25212525
"comment": comment,
2522-
"fastmath": fastmath,
25232526
},
25242527
)
25252528

@@ -3037,15 +3040,15 @@ class RdRsRsFloatFloatIntegerOperationWithFastMath(RISCVInstruction, ABC):
30373040
rd = result_def(IntRegisterType)
30383041
rs1 = operand_def(FloatRegisterType)
30393042
rs2 = operand_def(FloatRegisterType)
3040-
fastmath = opt_attr_def(FastMathFlagsAttr)
3043+
fastmath = opt_prop_def(FastMathFlagsAttr)
30413044

30423045
def __init__(
30433046
self,
30443047
rs1: Operation | SSAValue,
30453048
rs2: Operation | SSAValue,
30463049
*,
30473050
rd: IntRegisterType | str | None = None,
3048-
fastmath: FastMathFlagsAttr | None = None,
3051+
fastmath: FastMathFlagsAttr = FastMathFlagsAttr("none"),
30493052
comment: str | StringAttr | None = None,
30503053
):
30513054
if rd is None:
@@ -3057,8 +3060,10 @@ def __init__(
30573060

30583061
super().__init__(
30593062
operands=[rs1, rs2],
3060-
attributes={
3063+
properties={
30613064
"fastmath": fastmath,
3065+
},
3066+
attributes={
30623067
"comment": comment,
30633068
},
30643069
result_types=[rd],
@@ -3070,12 +3075,12 @@ def assembly_line_args(self) -> tuple[AssemblyInstructionArg, ...]:
30703075
@classmethod
30713076
def custom_parse_attributes(cls, parser: Parser) -> dict[str, Attribute]:
30723077
attributes = dict[str, Attribute]()
3073-
flags = FastMathFlagsAttr("none")
3078+
fast = FastMathFlagsAttr("none")
30743079
if parser.parse_optional_keyword("fastmath") is not None:
3075-
flags = FastMathFlagsAttr(FastMathFlagsAttr.parse_parameter(parser))
3076-
if flags != FastMathFlagsAttr("none"):
3077-
attributes["fastmath"] = flags
3078-
cls.fastmath = flags
3080+
fast = FastMathFlagsAttr(FastMathFlagsAttr.parse_parameter(parser))
3081+
if fast != FastMathFlagsAttr("none"):
3082+
attributes["fastmath"] = fast
3083+
cls.fastmath = fast
30793084
return attributes
30803085

30813086
def custom_print_attributes(self, printer: Printer) -> Set[str]:

0 commit comments

Comments
 (0)