Skip to content
10 changes: 0 additions & 10 deletions doc/user_guide/transformations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -344,11 +344,6 @@ can be found in the API-specific sections).
:members: apply
:no-index:

.. warning:: This transformation assumes that the MAX Intrinsic acts on
PSyIR Real scalar data and does not check that this is
not the case. Once issue #658 is on master then this
limitation can be fixed.

####

.. autoclass:: psyclone.psyir.transformations.Maxval2LoopTrans
Expand All @@ -361,11 +356,6 @@ can be found in the API-specific sections).
:members: apply
:no-index:

.. warning:: This transformation assumes that the MIN Intrinsic acts on
PSyIR Real scalar data and does not check that this is
not the case. Once issue #658 is on master then this
limitation can be fixed.

####

.. autoclass:: psyclone.psyir.transformations.Minval2LoopTrans
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,13 @@
from abc import ABC
import warnings

from psyclone.psyir.nodes import BinaryOperation, Assignment, \
Reference, IfBlock
from psyclone.psyir.symbols import DataSymbol, REAL_TYPE
from psyclone.psyir.transformations.intrinsics.intrinsic2code_trans import \
Intrinsic2CodeTrans
from psyclone.psyir.nodes import (
BinaryOperation, Assignment, Reference, IfBlock
)
from psyclone.psyir.symbols import DataSymbol
from psyclone.psyir.transformations.intrinsics.intrinsic2code_trans import (
Intrinsic2CodeTrans
)
from psyclone.utils import transformation_documentation_wrapper


Expand Down Expand Up @@ -85,6 +87,19 @@ def __init__(self):
super().__init__()
self._compare_operator = None

def validate(self, node, options=None):
'''
Check that it is safe to apply the transformation to the supplied node.

:param node: the SIGN call to transform.
:type node: :py:class:`psyclone.psyir.nodes.IntrinsicCall`
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typehints please.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added, also added the kwargs that I'd missed and fixed the typehints. I removed the options typehints since they're deprecated now.

:param options: any of options for the transformation.
:type options: dict[str, Any]

'''
super().validate(node, options=options)
super()._validate_scalar_arg(node)

def apply(self, node, options=None, **kwargs):
'''Apply this utility transformation to the specified node. This node
must be a MIN or MAX IntrinsicCall. The intrinsic is converted to
Expand Down Expand Up @@ -132,21 +147,14 @@ def apply(self, node, options=None, **kwargs):
symbol_table = node.scope.symbol_table
assignment = node.ancestor(Assignment)

# Create a temporary result variable. There is an assumption
# here that the Intrinsic returns a PSyIR real type. This
# might not be what is wanted (e.g. the args might PSyIR
# integers), or there may be errors (arguments are of
# different types) but this can't be checked as we don't have
# appropriate methods to query nodes (see #658).
# Create two temporary variables.
result_type = node.arguments[0].datatype
res_var_symbol = symbol_table.new_symbol(
f"res_{self._intrinsic.name.lower()}",
symbol_type=DataSymbol, datatype=REAL_TYPE)
# Create a temporary variable. Again there is an
# assumption here about the datatype - please see previous
# comment (associated issue #658).
symbol_type=DataSymbol, datatype=result_type)
tmp_var_symbol = symbol_table.new_symbol(
f"tmp_{self._intrinsic.name.lower()}",
symbol_type=DataSymbol, datatype=REAL_TYPE)
symbol_type=DataSymbol, datatype=result_type)

# Replace intrinsic with a temporary (res_var).
node.replace_with(Reference(res_var_symbol))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ def test_apply(fortran_reader, fortran_writer):
integer :: j
integer :: k
integer :: l
real :: res_max
real :: tmp_max
integer :: res_max
integer :: tmp_max
res_max = i
tmp_max = j
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ def test_apply(fortran_reader, fortran_writer):
integer :: j
integer :: k
integer :: l
real :: res_min
real :: tmp_min
integer :: res_min
integer :: tmp_min
res_min = i
tmp_min = j
Expand Down
Loading