psyclone.psyir.transformations.hoist_trans

This module contains the HoistTrans transformation. HoistTrans moves an assignment out of a parent loop if it is safe to do so. Hoist is a name that is often used to describe this type of transformation.

Classes

  • HoistTrans: This transformation takes an assignment and moves it outside of

class psyclone.psyir.transformations.hoist_trans.HoistTrans

This transformation takes an assignment and moves it outside of its parent loop if it is valid to do so. For example:

>>> from psyclone.psyir.backend.fortran import FortranWriter
>>> from psyclone.psyir.frontend.fortran import FortranReader
>>> from psyclone.psyir.nodes import Assignment
>>> from psyclone.psyir.transformations import HoistTrans
>>> code = ("program test\n"
...         "  integer :: i,j,n\n"
...         "  real :: a(n,n)\n"
...         "  real value\n"
...         "  do i=1,n\n"
...         "    value = 1.0\n"
...         "    do j=1,n\n"
...         "      a(i,j) = value\n"
...         "    end do\n"
...         "  end do\n"
...         "end program\n")
>>> psyir = FortranReader().psyir_from_source(code)
>>> hoist = HoistTrans()
>>> hoist.apply(psyir.walk(Assignment)[0])
>>> print(FortranWriter()(psyir))
program test
  integer :: i
  integer :: j
  integer :: n
  real, dimension(n,n) :: a
  real :: value

  value = 1.0
  do i = 1, n, 1
    do j = 1, n, 1
      a(i,j) = value
    enddo
  enddo

end program test

Inheritance

Inheritance diagram of HoistTrans
apply(node, options=None)

Applies the hoist transformation to the supplied assignment node within a loop, moving the assignment outside of the loop if it is valid to do so. Issue #1445 will also look to extend this transformation to other types of node.

Parameters:
  • node (subclass of psyclone.psyir.nodes.Assignment) – target PSyIR node.

  • options (Optional[Dict[str, Any]]) – a dictionary with options for transformations.

validate(node, options=None)

Checks that the supplied node is a valid target for a hoist transformation. At this stage only an assignment statement is allowed to be hoisted, see #1445. It should also be tested if there is a directive outside of the loop, see #1446

Parameters:
  • node (subclass of psyclone.psyir.nodes.Assignment) – target PSyIR node.

  • options (Optional[Dict[str, Any]]) – a dictionary with options for transformations.

Raises: