Skip to content

Commit

Permalink
refactor[next]: Move iterator utils to dedicated module (#1371)
Browse files Browse the repository at this point in the history
Move `gt4py.next.iterator.ir_makers` and `gt4py.next.iterator.transforms.common_pattern_matcher` into a new module named `gt4py.next.iterator.ir_utils`. Just a small refactoring in preparation of #1350.
  • Loading branch information
tehrengruber authored Nov 29, 2023
1 parent 91307b1 commit 4c02286
Show file tree
Hide file tree
Showing 24 changed files with 51 additions and 24 deletions.
7 changes: 6 additions & 1 deletion src/gt4py/next/ffront/decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,12 @@
from gt4py.next.ffront.past_to_itir import ProgramLowering
from gt4py.next.ffront.source_utils import SourceDefinition, get_closure_vars_from_function
from gt4py.next.iterator import ir as itir
from gt4py.next.iterator.ir_makers import literal_from_value, promote_to_const_iterator, ref, sym
from gt4py.next.iterator.ir_utils.ir_makers import (
literal_from_value,
promote_to_const_iterator,
ref,
sym,
)
from gt4py.next.program_processors import processor_interface as ppi
from gt4py.next.program_processors.runners import roundtrip
from gt4py.next.type_system import type_info, type_specifications as ts, type_translation
Expand Down
3 changes: 2 additions & 1 deletion src/gt4py/next/ffront/foast_to_itir.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
)
from gt4py.next.ffront.fbuiltins import FUN_BUILTIN_NAMES, MATH_BUILTIN_NAMES, TYPE_BUILTIN_NAMES
from gt4py.next.ffront.foast_introspection import StmtReturnKind, deduce_stmt_return_kind
from gt4py.next.iterator import ir as itir, ir_makers as im
from gt4py.next.iterator import ir as itir
from gt4py.next.iterator.ir_utils import ir_makers as im
from gt4py.next.type_system import type_info, type_specifications as ts


Expand Down
13 changes: 13 additions & 0 deletions src/gt4py/next/iterator/ir_utils/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# GT4Py - GridTools Framework
#
# Copyright (c) 2014-2023, ETH Zurich
# All rights reserved.
#
# This file is part of the GT4Py project and the GridTools framework.
# GT4Py is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the
# Free Software Foundation, either version 3 of the License, or any later
# version. See the LICENSE.txt file at the top-level directory of this
# distribution for a copy of the license or check <https://www.gnu.org/licenses/>.
#
# SPDX-License-Identifier: GPL-3.0-or-later
File renamed without changes.
3 changes: 2 additions & 1 deletion src/gt4py/next/iterator/pretty_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

from lark import lark, lexer as lark_lexer, visitors as lark_visitors

from gt4py.next.iterator import ir, ir_makers as im
from gt4py.next.iterator import ir
from gt4py.next.iterator.ir_utils import ir_makers as im


GRAMMAR = """
Expand Down
3 changes: 2 additions & 1 deletion src/gt4py/next/iterator/tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from gt4py._core import definitions as core_defs
from gt4py.eve import Node
from gt4py.next import common, iterator
from gt4py.next.iterator import builtins, ir_makers as im
from gt4py.next.iterator import builtins
from gt4py.next.iterator.ir import (
AxisLiteral,
Expr,
Expand All @@ -34,6 +34,7 @@
Sym,
SymRef,
)
from gt4py.next.iterator.ir_utils import ir_makers as im
from gt4py.next.type_system import type_info, type_specifications, type_translation


Expand Down
3 changes: 2 additions & 1 deletion src/gt4py/next/iterator/transforms/constant_folding.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
# SPDX-License-Identifier: GPL-3.0-or-later

from gt4py.eve import NodeTranslator
from gt4py.next.iterator import embedded, ir, ir_makers as im
from gt4py.next.iterator import embedded, ir
from gt4py.next.iterator.ir_utils import ir_makers as im


class ConstantFolding(NodeTranslator):
Expand Down
2 changes: 1 addition & 1 deletion src/gt4py/next/iterator/transforms/cse.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ def extract_subexpression(
Examples:
Default case for `(x+y) + ((x+y)+z)`:
>>> import gt4py.next.iterator.ir_makers as im
>>> import gt4py.next.iterator.ir_utils.ir_makers as im
>>> from gt4py.eve.utils import UIDGenerator
>>> expr = im.plus(im.plus("x", "y"), im.plus(im.plus("x", "y"), "z"))
>>> predicate = lambda subexpr, num_occurences: num_occurences > 1
Expand Down
5 changes: 3 additions & 2 deletions src/gt4py/next/iterator/transforms/global_tmps.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@
from gt4py.eve import Coerced, NodeTranslator
from gt4py.eve.traits import SymbolTableTrait
from gt4py.eve.utils import UIDGenerator
from gt4py.next.iterator import ir, ir_makers as im, type_inference
from gt4py.next.iterator import ir, type_inference
from gt4py.next.iterator.ir_utils import ir_makers as im
from gt4py.next.iterator.ir_utils.common_pattern_matcher import is_applied_lift
from gt4py.next.iterator.pretty_printer import PrettyPrinter
from gt4py.next.iterator.transforms import trace_shifts
from gt4py.next.iterator.transforms.common_pattern_matcher import is_applied_lift
from gt4py.next.iterator.transforms.cse import extract_subexpression
from gt4py.next.iterator.transforms.eta_reduction import EtaReduction
from gt4py.next.iterator.transforms.inline_lambdas import InlineLambdas
Expand Down
2 changes: 1 addition & 1 deletion src/gt4py/next/iterator/transforms/inline_lambdas.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

from gt4py.eve import NodeTranslator
from gt4py.next.iterator import ir
from gt4py.next.iterator.transforms.common_pattern_matcher import is_applied_lift
from gt4py.next.iterator.ir_utils.common_pattern_matcher import is_applied_lift
from gt4py.next.iterator.transforms.remap_symbols import RemapSymbolRefs, RenameSymbols
from gt4py.next.iterator.transforms.symbol_ref_utils import CountSymbolRefs

Expand Down
3 changes: 2 additions & 1 deletion src/gt4py/next/iterator/transforms/inline_lifts.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@

import gt4py.eve as eve
from gt4py.eve import NodeTranslator, traits
from gt4py.next.iterator import ir, ir_makers as im
from gt4py.next.iterator import ir
from gt4py.next.iterator.ir_utils import ir_makers as im
from gt4py.next.iterator.transforms.inline_lambdas import inline_lambda


Expand Down
2 changes: 1 addition & 1 deletion src/gt4py/next/iterator/transforms/symbol_ref_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def apply(
Count references to given or all symbols in scope.
Examples:
>>> import gt4py.next.iterator.ir_makers as im
>>> import gt4py.next.iterator.ir_utils.ir_makers as im
>>> expr = im.plus(im.plus("x", "y"), im.plus(im.plus("x", "y"), "z"))
>>> CountSymbolRefs.apply(expr)
{'x': 2, 'y': 2, 'z': 1}
Expand Down
2 changes: 1 addition & 1 deletion src/gt4py/next/iterator/transforms/unroll_reduce.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from gt4py.eve.utils import UIDGenerator
from gt4py.next import common
from gt4py.next.iterator import ir as itir
from gt4py.next.iterator.transforms.common_pattern_matcher import is_applied_lift
from gt4py.next.iterator.ir_utils.common_pattern_matcher import is_applied_lift


def _is_shifted(arg: itir.Expr) -> TypeGuard[itir.FunCall]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
from gt4py.next.ffront.ast_passes import single_static_assign as ssa
from gt4py.next.ffront.foast_to_itir import FieldOperatorLowering
from gt4py.next.ffront.func_to_foast import FieldOperatorParser
from gt4py.next.iterator import ir as itir, ir_makers as im
from gt4py.next.iterator import ir as itir
from gt4py.next.iterator.ir_utils import ir_makers as im
from gt4py.next.type_system import type_specifications as ts, type_translation


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
import numpy as np

import gt4py.next as gtx
from gt4py.next.iterator import ir, ir_makers as im, type_inference as ti
from gt4py.next.iterator import ir, type_inference as ti
from gt4py.next.iterator.ir_utils import ir_makers as im


def test_unsatisfiable_constraints():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
#
# SPDX-License-Identifier: GPL-3.0-or-later

import pytest

from gt4py.next.iterator import ir, ir_makers as im
from gt4py.next.iterator.ir_utils import ir_makers as im
from gt4py.next.iterator.transforms.collapse_tuple import CollapseTuple


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#
# SPDX-License-Identifier: GPL-3.0-or-later

from gt4py.next.iterator import ir_makers as im
from gt4py.next.iterator.ir_utils import ir_makers as im
from gt4py.next.iterator.transforms.constant_folding import ConstantFolding


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
import textwrap

from gt4py.eve.utils import UIDGenerator
from gt4py.next.iterator import ir, ir_makers as im
from gt4py.next.iterator import ir
from gt4py.next.iterator.ir_utils import ir_makers as im
from gt4py.next.iterator.transforms.cse import (
CommonSubexpressionElimination as CSE,
extract_subexpression,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@

import gt4py.next as gtx
from gt4py.eve.utils import UIDs
from gt4py.next.iterator import ir, ir_makers as im
from gt4py.next.iterator import ir
from gt4py.next.iterator.ir_utils import ir_makers as im
from gt4py.next.iterator.transforms.global_tmps import (
AUTO_DOMAIN,
FencilWithTemporaries,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import pytest

from gt4py.next.iterator import ir_makers as im
from gt4py.next.iterator.ir_utils import ir_makers as im
from gt4py.next.iterator.transforms.inline_lambdas import InlineLambdas


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import pytest

from gt4py.next.iterator import ir_makers as im
from gt4py.next.iterator.ir_utils import ir_makers as im
from gt4py.next.iterator.transforms.inline_lifts import InlineLifts


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#
# SPDX-License-Identifier: GPL-3.0-or-later

from gt4py.next.iterator import ir_makers as im
from gt4py.next.iterator.ir_utils import ir_makers as im
from gt4py.next.iterator.transforms.propagate_deref import PropagateDeref


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
#
# SPDX-License-Identifier: GPL-3.0-or-later

from gt4py.next.iterator import ir, ir_makers as im
from gt4py.next.iterator import ir
from gt4py.next.iterator.ir_utils import ir_makers as im
from gt4py.next.iterator.transforms.trace_shifts import Sentinel, TraceShifts


Expand Down

0 comments on commit 4c02286

Please sign in to comment.