psyclone.psyir.transformations.loop_swap_trans#
This module provides the loop swap transformation.
Classes#
LoopSwapTrans: Provides a loop-swap transformation, e.g.:
- 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.tests.utilities import get_psylayer_schedule >>> filename = "eg1/shallow_alg.f90" >>> schedule = get_psylayer_schedule(filename, api="gocean-examples") >>> >>> from psyclone.psyir.transformations import LoopSwapTrans >>> from psyclone.psyir.nodes import Loop >>> swap = LoopSwapTrans() >>> swap.apply(schedule.walk(Loop)[0])
Inheritance

- apply(node, options=None, **kwargs)[source]#
The argument
outermust 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:
TransformationError – if the supplied node does not allow a loop swap to be done.
TransformationError – if either the inner or outer loop has a symbol table.