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
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("gocean1.0").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
- apply(node, options=None)
The argument
outer
must be a loop which has exactly one inner loop. This transform then swaps the outer and inner loop.- Parameters:
outer (
psyclone.psyir.nodes.Loop
) – the node representing the outer loop.options (Optional[Dict[str, Any]]) – a dictionary with options for transformations.
- Raises:
TransformationError – if the supplied node does not allow a loop swap to be done.
- validate(node, options=None)
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_outer (py:class:psyclone.psyir.nodes.Loop) – a Loop node from an AST.
options (Optional[Dict[str, Any]]) – a dictionary with options for transformations.
- 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.