psyclone.psyir.transformations.loop_swap_trans#

This module provides the loop swap transformation.

Classes#

class psyclone.psyir.transformations.loop_swap_trans.LoopSwapTrans[source]#

Provides a loop-swap transformation, e.g.:

DO j=1, m
    DO i=1, n

becomes:

DO i=1, n
    DO j=1, m

This transform is used as follows:

>>> from psyclone.parse.algorithm import parse
>>> from psyclone.psyGen import PSyFactory
>>> ast, invokeInfo = parse("shallow_alg.f90")
>>> psy = PSyFactory("gocean").create(invokeInfo)
>>> schedule = psy.invokes.get('invoke_0').schedule
>>> # Uncomment the following line to see a text view of the schedule
>>> # print(schedule.view())
>>>
>>> from psyclone.transformations import LoopSwapTrans
>>> swap = LoopSwapTrans()
>>> swap.apply(schedule.children[0])
>>> # Uncomment the following line to see a text view of the schedule
>>> # print(schedule.view())

Inheritance

Inheritance diagram of LoopSwapTrans
apply(node, options=None, **kwargs)[source]#

The argument outer must be a loop which has exactly one inner loop. This transform then swaps the outer and inner loop.

Parameters:
  • node (Loop) – the node representing the outer loop.

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

  • node_type_check (bool) – If the type of nodes enclosed in the loop should be tested to avoid including unsupported nodes in the transformation.

  • verbose (bool) – whether to log the reason the validation failed, at the moment with a comment in the provided PSyIR node.

Raises:

TransformationError – if the supplied node does not allow a loop swap to be done.

validate(node, options=None, **kwargs)[source]#

Checks if the given node contains a valid Fortran structure to allow swapping loops. This means the node must represent a loop, and it must have exactly one child that is also a loop.

Parameters:
  • node (Loop) – the outer Loop Node of a loop nest.

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

  • node_type_check (bool) – If the type of nodes enclosed in the loop should be tested to avoid including unsupported nodes in the transformation.

  • verbose (bool) – whether to log the reason the validation failed, at the moment with a comment in the provided PSyIR node.

Raises: