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#

class psyclone.psyir.transformations.hoist_loop_bound_expr_trans.HoistLoopBoundExprTrans[source]#

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

Inheritance diagram of HoistLoopBoundExprTrans
apply(node, options=None)[source]#

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)[source]#

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: