psyclone.domain.nemo.transformations.nemo_allarrayaccess2loop_trans
Module providing a transformation that transforms all constant index accesses to an array (i.e. ones that do not contain loop iterators) to single trip loops.
Classes
NemoAllArrayAccess2LoopTrans
: Provides a transformation from a PSyIR Assignment containing
- class psyclone.domain.nemo.transformations.nemo_allarrayaccess2loop_trans.NemoAllArrayAccess2LoopTrans
Provides a transformation from a PSyIR Assignment containing constant index accesses to an array into single trip loops: For example:
>>> from psyclone.domain.nemo.transformations import \ ... NemoAllArrayAccess2LoopTrans >>> 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,10), b(10,10)\n" ... " integer :: n\n" ... " a(1,n-1) = b(1,n-1)\n" ... "end program example\n") >>> psyir = FortranReader().psyir_from_source(code) >>> assignment = psyir.walk(Assignment)[0] >>> NemoAllArrayAccess2LoopTrans().apply(assignment) >>> print(FortranWriter()(psyir)) program example real, dimension(10,10) :: a real, dimension(10,10) :: b integer :: n integer :: ji integer :: jj do ji = 1, 1, 1 do jj = n - 1, n - 1, 1 a(ji,jj) = b(ji,jj) enddo enddo end program example
Inheritance
- apply(node, options=None)
Apply the NemoAllArrayAccess2Loop transformation if the supplied node is an Assignment with an Array Reference on its left-hand-side. Each constant array index access (i.e. one not containing a loop iterator or a range) is then transformed into an iterator and the assignment placed within a single trip loop, subject to any constraints in the NemoArrayAccess2Loop transformation.
If any of the NemoAllArrayAccess2Loop constraints are not satisfied for a loop index then this transformation does nothing for that index and silently moves to the next.
- Parameters:
node (
psyclone.psyir.nodes.Assignment
) – an assignment.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.
- property name
- Returns:
the name of the transformation as a string.
- Return type:
str
- validate(node, options=None)
Perform any checks to ensure that it is valid to apply the NemoAllArrayAccess2LoopTrans 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. No options are used in this transformation. This is an optional argument that defaults to None.