psyclone.psyir.transformations.hoist_loop_bound_expr_trans
This module contains the HoistLoopBoundExprTrans transformation. This transformation moves complex bounds expressions out of the loop construct and places them in integer scalar assignments before the loop.
Classes
HoistLoopBoundExprTrans
: This transformation moves complex bounds expressions out of the loop
- class psyclone.psyir.transformations.hoist_loop_bound_expr_trans.HoistLoopBoundExprTrans
This transformation moves complex bounds expressions out of the loop construct and places them in integer scalar assignments before the loop.
>>> from psyclone.psyir.backend.fortran import FortranWriter >>> from psyclone.psyir.frontend.fortran import FortranReader >>> from psyclone.psyir.nodes import Loop >>> from psyclone.psyir.transformations import HoistTrans >>> code = ("program test\n" ... " use mymod, only: mytype\n" ... " integer :: i,j,n\n" ... " real :: a(n)\n" ... " do i=mytype%start, UBOUND(a,1)\n" ... " a(i) = 1.0\n" ... " end do\n" ... "end program\n") >>> psyir = FortranReader().psyir_from_source(code) >>> hoist = HoistLoopBoundExprTrans() >>> hoist.apply(psyir.walk(Loop)[0]) >>> print(FortranWriter()(psyir)) program test use mymod, only : mytype integer :: i integer :: j integer :: n real, dimension(n) :: a integer :: loop_bound integer :: loop_bound_1 loop_bound_1 = UBOUND(a, 1) loop_bound = mytype%start do i = loop_bound, loop_bound_1, 1 a(i) = 1.0 enddo end program test
Inheritance
- apply(node, options=None)
Move complex bounds expressions out of the given loop construct and place them in integer scalar assignments before the loop.
- Parameters:
node (
psyclone.psyir.nodes.Loop
) – target PSyIR loop.options (Dict[str, Any]) – a dictionary with options for transformations.
- validate(node, options=None)
Checks that the supplied node is a valid target for the transformation.
- Parameters:
node (
psyclone.psyir.nodes.Loop
) – target PSyIR loop.options (Dict[str, Any]) – a dictionary with options for transformations.
- Raises:
TransformationError – if the supplied node does not have an ancestor Routine.
TransformationError – if the supplied node is directly inside a Directive Schedule.