psyclone.domain.nemo.transformations.nemo_allarrayrange2loop_trans

Module providing a transformation from an Assignment node containing an Array Reference node in its left-hand-side which in turn has at least one PSyIR Range node specifying an access to an array index (equivalent to an array assignment statement in Fortran) to the equivalent loop representation using the required number of NemoLoop nodes.

Classes

class psyclone.domain.nemo.transformations.nemo_allarrayrange2loop_trans.NemoAllArrayRange2LoopTrans

Provides a transformation for all PSyIR Array Ranges in an assignment to PSyIR NemoLoops. For example:

>>> from psyclone.parse.algorithm import parse
>>> from psyclone.psyGen import PSyFactory
>>> api = "nemo"
>>> filename = "tra_adv.F90" # examples/nemo/code
>>> 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.domain.nemo.transformations import             NemoAllArrayRange2LoopTrans
>>>
>>> print(schedule.view())
>>> trans = NemoAllArrayRange2LoopTrans()
>>> for assignment in schedule.walk(Assignment):
>>>     trans.apply(assignment)
>>> print(schedule.view())

Inheritance

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

Apply the NemoAllArrayRange2Loop transformation to the specified node if the node is an Assignment and the left-hand-side of the assignment is an Array Reference containing at least one Range node specifying an access to an array index. If this is the case then all Range nodes within array references within the assignment are replaced with references to the appropriate loop indices. The appropriate number of NemoLoop loops are also placed around the modified assignment statement.

The name of each loop index is taken from the PSyclone configuration file if a name exists for the particular array index, otherwise a new name is generated. The bounds of each loop are taken from the Range node if they are provided. If not, the loop bounds are taken from the PSyclone configuration file if a bounds value is supplied. If not, the LBOUND or UBOUND intrinsics are used as appropriate. The type of the NemoLoop is also taken from the configuration file if it is supplied for that index, otherwise it is specified as being “unknown”.

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

  • options (Optional[Dict[str, Any]]) – a dictionary with options for transformations. No options are used in this transformation. This is an optional argument that defaults to None.

  • options["verbose"] (bool) – whether to print out the reason why the inner transformation was not applied. This is useful because this transfomation succeeds even if one of the inner transformations fails, and therefor the reason why the inner transformation failed is not propagated.

  • 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.

Return type:

str

validate(node, options=None)

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

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

  • options (Optional[Dict[str, Any]]) – a dictionary with options for transformations. No options are used in this transformation. This is an optional argument that defaults to None.

Raises:

TransformationError – if the supplied node is not an Assignment.