psyclone.psyir.transformations.arrayaccess2loop_trans
Module providing a transformation that transforms a constant index access to an array (i.e. one that does not contain a loop iterator) to a single trip loop. The node representing the constant index access is provided to the apply method of the transformation to indicate which array index should be transformed.
Classes
ArrayAccess2LoopTrans
: Provides a transformation to transform a constant index access to
- class psyclone.psyir.transformations.arrayaccess2loop_trans.ArrayAccess2LoopTrans
Provides a transformation to transform a constant index access to an array (i.e. one that does not contain a loop iterator) to a single trip loop. For example:
>>> from psyclone.psyir.transformations import ArrayAccess2LoopTrans >>> from psyclone.psyir.backend.fortran import FortranWriter >>> from psyclone.psyir.frontend.fortran import FortranReader >>> from psyclone.psyir.nodes import Assignment >>> code = ("program example\n" ... " real a(10)\n" ... " a(1) = 0.0\n" ... "end program example\n") >>> psyir = FortranReader().psyir_from_source(code) >>> assignment = psyir.walk(Assignment)[0] >>> ArrayAccess2LoopTrans().apply(assignment.lhs.children[0]) >>> print(FortranWriter()(psyir)) program example real, dimension(10) :: a integer :: ji do ji = 1, 1, 1 a(ji) = 0.0 enddo end program example
Inheritance
- apply(node, options=None)
Apply the ArrayAccess2Loop transformation if the supplied node is an access to an array index within an Array Reference that is on the left-hand-side of an Assignment node. The access must be a scalar (i.e. not a range) and must not include a loop variable (as we are transforming a single access to a loop).
If the constraints are satisfied then the array access is replaced with a loop iterator and a single trip loop. The new loop will be placed immediately around the assignment.
- Parameters:
node (
psyclone.psyir.nodes.Node
) – an array index.options (Optional[Dict[str, Any]]) – a dictionary with options for transformations. This is an optional argument that defaults to None.
- validate(node, options=None)
Perform various checks to ensure that it is valid to apply the ArrayAccess2LoopTrans transformation to the supplied PSyIR Node.
- Parameters:
node (
psyclone.psyir.nodes.Node
) – the node that is being checked.options (Optional[Dict[str, Any]]) – a dictionary with options for transformations. This is an optional argument that defaults to None.