psyclone.psyir.transformations.arrayrange2loop_trans

Module providing a transformation from a PSyIR Array Range to a PSyIR Loop. This could be useful for e.g. performance reasons, to allow further transformations e.g. loop fusion or if the back-end does not support array ranges.

By default the transformation will reject character arrays, though this can be overriden by setting the allow_string option to True. Note that PSyclone expresses syntax such as character(LEN=100) as UnsupportedFortranType, and this transformation will convert unknown or unsupported types to loops.

Classes

class psyclone.psyir.transformations.arrayrange2loop_trans.ArrayRange2LoopTrans

Provides a transformation from a PSyIR Array Range to a PSyIR Loop. For example:

>>> from psyclone.parse.algorithm import parse
>>> from psyclone.psyGen import PSyFactory
>>> api = "nemo"
>>> filename = "tra_adv_compute.F90"
>>> ast, invoke_info = parse(filename, api=api)
>>> psy = PSyFactory(api).create(invoke_info)
>>> schedule = psy.invokes.invoke_list[0].schedule
>>>
>>> from psyclone.psyir.nodes import Assignment
>>> from psyclone.psyir.transformations import ArrayRange2LoopTrans,     >>>     TransformationError
>>>
>>> print(schedule.view())
>>> trans = ArrayRange2LoopTrans()
>>> for assignment in schedule.walk(Assignment):
>>>     while True:
>>>         try:
>>>             trans.apply(assignment)
>>>         except TransformationError:
>>>             break
>>> print(schedule.view())

Inheritance

Inheritance diagram of ArrayRange2LoopTrans
apply(node, options=None)

Apply the ArrayRange2Loop transformation to the specified node. The node must be an assignment. The rightmost range node in each array within the assignment is replaced with a loop index and the assignment is placed within a loop iterating over that index. The bounds of the loop are determined from the bounds of the array range on the left hand side of the assignment.

Parameters:
  • node (psyclone.psyir.nodes.Assignment) – an Assignment node.

  • options["allow_string"] (bool) – whether to allow the transformation on a character type array range. Defaults to False.

property name
Returns:

the name of the transformation as a string.

Return type:

str

validate(node, options=None)

Perform various checks to ensure that it is valid to apply the ArrayRange2LoopTrans transformation to the supplied PSyIR Node.

By default the validate function will throw an TransofmrationError on character arrays, though this can be overriden by setting the allow_string option to True. Note that PSyclone expresses syntax such as character(LEN=100) as UnsupportedFortranType, and this transformation will convert unknown or unsupported types to loops.

Parameters:
  • node (psyclone.psyir.nodes.Assignment) – the node that is being checked.

  • options (Optional[Dict[str, Any]]) – a dictionary with options for transformations

  • options["allow_string"] (bool) – whether to allow the transformation on a character type array range. Defaults to False.

Raises:
  • TransformationError – if the node argument is not an Assignment.

  • TransformationError – if the node argument is an Assignment whose left hand side is not an ArrayReference.

  • TransformationError – if the node argument is an Assignment whose left hand side is an ArrayReference that does not have Range specifying the access to at least one of its dimensions.

  • TransformationError – if two or more of the loop ranges in the assignment are different or are not known to be the same.

  • TransformationError – if node contains a character type child and the allow_strings option is not set.