Skip to content

Commit

Permalink
misc: split dialects.utils into multiple files (#3472)
Browse files Browse the repository at this point in the history
It feels like a logical split, and leaves space for some upcoming shared
dialects helpers.
  • Loading branch information
superlopuh authored Nov 20, 2024
1 parent 746db81 commit 4b08fcd
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 41 deletions.
16 changes: 9 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,19 @@ ignore = [
max-line-length = 300

[tool.ruff.lint.flake8-tidy-imports.banned-api]
"xdsl.parser.core".msg = "Use xdsl.parser instead."
"xdsl.parser.attribute_parser".msg = "Use xdsl.parser instead."
"xdsl.parser.affine_parser".msg = "Use xdsl.parser instead."
"xdsl.dialects.utils.fast_math".msg = "Use xdsl.dialects.utils instead"
"xdsl.dialects.utils.format".msg = "Use xdsl.dialects.utils instead"
"xdsl.ir.affine.affine_expr".msg = "Use xdsl.ir.affine instead"
"xdsl.ir.affine.affine_map".msg = "Use xdsl.ir.affine instead"
"xdsl.ir.affine.affine_set".msg = "Use xdsl.ir.affine instead"
"xdsl.ir.core".msg = "Use xdsl.ir instead."
"xdsl.irdl.attributes".msg = "Use xdsl.irdl instead"
"xdsl.irdl.common".msg = "Use xdsl.irdl instead"
"xdsl.irdl.constraints".msg = "Use xdsl.irdl instead"
"xdsl.irdl.attributes".msg = "Use xdsl.irdl instead"
"xdsl.irdl.operations".msg = "Use xdsl.irdl instead"
"xdsl.ir.affine.affine_expr".msg = "Use xdsl.ir.affine instead"
"xdsl.ir.affine.affine_map".msg = "Use xdsl.ir.affine instead"
"xdsl.ir.affine.affine_set".msg = "Use xdsl.ir.affine instead"
"xdsl.parser.affine_parser".msg = "Use xdsl.parser instead."
"xdsl.parser.attribute_parser".msg = "Use xdsl.parser instead."
"xdsl.parser.core".msg = "Use xdsl.parser instead."


[tool.ruff.lint.per-file-ignores]
Expand Down
4 changes: 4 additions & 0 deletions xdsl/dialects/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# TID 251 enforces to not import from those
# We need to skip it here to allow importing from here instead.
from .fast_math import * # noqa: TID251
from .format import * # noqa: TID251
29 changes: 29 additions & 0 deletions xdsl/dialects/utils/fast_math.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from abc import ABC
from dataclasses import dataclass

from xdsl.ir import BitEnumAttribute
from xdsl.utils.str_enum import StrEnum


class FastMathFlag(StrEnum):
"""
Values specifying fast math behaviour of an arithmetic operation.
"""

REASSOC = "reassoc"
NO_NANS = "nnan"
NO_INFS = "ninf"
NO_SIGNED_ZEROS = "nsz"
ALLOW_RECIP = "arcp"
ALLOW_CONTRACT = "contract"
APPROX_FUNC = "afn"


@dataclass(frozen=True, init=False)
class FastMathAttrBase(BitEnumAttribute[FastMathFlag], ABC):
"""
Base class for attributes defining fast math behavior of arithmetic operations.
"""

none_value = "none"
all_value = "fast"
34 changes: 0 additions & 34 deletions xdsl/dialects/utils.py → xdsl/dialects/utils/format.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
from abc import ABC
from collections.abc import Iterable, Sequence
from dataclasses import dataclass
from typing import Generic

from xdsl.dialects.builtin import (
Expand All @@ -14,7 +12,6 @@
from xdsl.ir import (
Attribute,
AttributeInvT,
BitEnumAttribute,
BlockArgument,
Operation,
Region,
Expand All @@ -23,7 +20,6 @@
from xdsl.irdl import IRDLOperation, var_operand_def
from xdsl.parser import Parser, UnresolvedOperand
from xdsl.printer import Printer
from xdsl.utils.str_enum import StrEnum


def print_call_op_like(
Expand Down Expand Up @@ -345,33 +341,3 @@ def parse_dynamic_index_list_without_types(
values.append(value_or_index)

return values, indices


# region Fast Math Flags


class FastMathFlag(StrEnum):
"""
Values specifying fast math behaviour of an arithmetic operation.
"""

REASSOC = "reassoc"
NO_NANS = "nnan"
NO_INFS = "ninf"
NO_SIGNED_ZEROS = "nsz"
ALLOW_RECIP = "arcp"
ALLOW_CONTRACT = "contract"
APPROX_FUNC = "afn"


@dataclass(frozen=True, init=False)
class FastMathAttrBase(BitEnumAttribute[FastMathFlag], ABC):
"""
Base class for attributes defining fast math behavior of arithmetic operations.
"""

none_value = "none"
all_value = "fast"


# endregion

0 comments on commit 4b08fcd

Please sign in to comment.