Reference Guide  2.5.0
psyclone.transformations.MoveTrans Class Reference
Inheritance diagram for psyclone.transformations.MoveTrans:
Collaboration diagram for psyclone.transformations.MoveTrans:

Public Member Functions

def __str__ (self)
 
def name (self)
 
def validate (self, node, location, options=None)
 
def apply (self, node, location, options=None)
 
- Public Member Functions inherited from psyclone.psyGen.Transformation
def apply (self, node, options=None)
 
def validate (self, node, options=None)
 

Detailed Description

Provides a transformation to move a node in the tree. For
example:

>>> from psyclone.parse.algorithm import parse
>>> from psyclone.psyGen import PSyFactory
>>> ast,invokeInfo=parse("dynamo.F90")
>>> psy=PSyFactory("dynamo0.3").create(invokeInfo)
>>> schedule=psy.invokes.get('invoke_v3_kernel_type').schedule
>>> # Uncomment the following line to see a text view of the schedule
>>> # print(schedule.view())
>>>
>>> from psyclone.transformations import MoveTrans
>>> trans=MoveTrans()
>>> trans.apply(schedule.children[0], schedule.children[2],
...             options = {"position":"after")
>>> # Uncomment the following line to see a text view of the schedule
>>> # print(schedule.view())

Nodes may only be moved to a new location with the same parent
and must not break any dependencies otherwise an exception is
raised.

Definition at line 1665 of file transformations.py.

Member Function Documentation

◆ apply()

def psyclone.transformations.MoveTrans.apply (   self,
  node,
  location,
  options = None 
)
Move the node represented by :py:obj:`node` before location
:py:obj:`location` (which is also a node) by default and after
if the optional `position` argument is set to 'after'.

:param node: the node to be moved.
:type node: :py:class:`psyclone.psyir.nodes.Node`
:param location: node before or after which the given node\
    should be moved.
:type location: :py:class:`psyclone.psyir.nodes.Node`
:param options: a dictionary with options for transformations.
:type options: Optional[Dict[str, Any]]
:param str options["position"]: either 'before' or 'after'.

:raises TransformationError: if the given node is not an instance \
    of :py:class:`psyclone.psyir.nodes.Node`
:raises TransformationError: if the location is not valid.

Definition at line 1730 of file transformations.py.

1730  def apply(self, node, location, options=None):
1731  '''Move the node represented by :py:obj:`node` before location
1732  :py:obj:`location` (which is also a node) by default and after
1733  if the optional `position` argument is set to 'after'.
1734 
1735  :param node: the node to be moved.
1736  :type node: :py:class:`psyclone.psyir.nodes.Node`
1737  :param location: node before or after which the given node\
1738  should be moved.
1739  :type location: :py:class:`psyclone.psyir.nodes.Node`
1740  :param options: a dictionary with options for transformations.
1741  :type options: Optional[Dict[str, Any]]
1742  :param str options["position"]: either 'before' or 'after'.
1743 
1744  :raises TransformationError: if the given node is not an instance \
1745  of :py:class:`psyclone.psyir.nodes.Node`
1746  :raises TransformationError: if the location is not valid.
1747 
1748  '''
1749  # pylint:disable=arguments-differ
1750 
1751  self.validate(node, location, options)
1752 
1753  if not options:
1754  options = {}
1755  position = options.get("position", "before")
1756 
1757  parent = node.parent
1758 
1759  my_node = parent.children.pop(node.position)
1760 
1761  location_index = location.position
1762  if position == "before":
1763  location.parent.children.insert(location_index, my_node)
1764  else:
1765  location.parent.children.insert(location_index+1, my_node)
1766 
1767 

References psyclone.domain.lfric.kernel.lfric_kernel_metadata.LFRicKernelMetadata.validate(), psyclone.transformations.MoveTrans.validate(), psyclone.transformations.Dynamo0p3AsyncHaloExchangeTrans.validate(), psyclone.domain.common.transformations.alg_invoke_2_psy_call_trans.AlgInvoke2PSyCallTrans.validate(), psyclone.domain.common.transformations.alg_trans.AlgTrans.validate(), psyclone.domain.common.transformations.kernel_module_inline_trans.KernelModuleInlineTrans.validate(), psyclone.domain.common.transformations.raise_psyir_2_alg_trans.RaisePSyIR2AlgTrans.validate(), psyclone.domain.gocean.transformations.gocean_const_loop_bounds_trans.GOConstLoopBoundsTrans.validate(), psyclone.domain.gocean.transformations.gocean_move_iteration_boundaries_inside_kernel_trans.GOMoveIterationBoundariesInsideKernelTrans.validate(), psyclone.domain.gocean.transformations.gocean_opencl_trans.GOOpenCLTrans.validate(), psyclone.domain.gocean.transformations.raise_psyir_2_gocean_kern_trans.RaisePSyIR2GOceanKernTrans.validate(), psyclone.domain.lfric.transformations.lfric_alg_invoke_2_psy_call_trans.LFRicAlgInvoke2PSyCallTrans.validate(), psyclone.domain.lfric.transformations.raise_psyir_2_lfric_kern_trans.RaisePSyIR2LFRicKernTrans.validate(), psyclone.domain.nemo.transformations.create_nemo_invoke_schedule_trans.CreateNemoInvokeScheduleTrans.validate(), psyclone.domain.nemo.transformations.create_nemo_psy_trans.CreateNemoPSyTrans.validate(), psyclone.domain.nemo.transformations.nemo_allarrayrange2loop_trans.NemoAllArrayRange2LoopTrans.validate(), psyclone.domain.nemo.transformations.nemo_arrayrange2loop_trans.NemoArrayRange2LoopTrans.validate(), psyclone.domain.nemo.transformations.nemo_outerarrayrange2loop_trans.NemoOuterArrayRange2LoopTrans.validate(), psyclone.psyad.transformations.assignment_trans.AssignmentTrans.validate(), psyclone.psyGen.Transformation.validate(), psyclone.psyir.transformations.acc_update_trans.ACCUpdateTrans.validate(), psyclone.psyir.transformations.allarrayaccess2loop_trans.AllArrayAccess2LoopTrans.validate(), psyclone.psyir.transformations.arrayaccess2loop_trans.ArrayAccess2LoopTrans.validate(), psyclone.psyir.transformations.arrayrange2loop_trans.ArrayRange2LoopTrans.validate(), psyclone.psyir.transformations.chunk_loop_trans.ChunkLoopTrans.validate(), psyclone.psyir.transformations.fold_conditional_return_expressions_trans.FoldConditionalReturnExpressionsTrans.validate(), psyclone.psyir.transformations.hoist_local_arrays_trans.HoistLocalArraysTrans.validate(), psyclone.psyir.transformations.hoist_loop_bound_expr_trans.HoistLoopBoundExprTrans.validate(), psyclone.psyir.transformations.hoist_trans.HoistTrans.validate(), psyclone.psyir.transformations.inline_trans.InlineTrans.validate(), psyclone.psyir.transformations.intrinsics.array_reduction_base_trans.ArrayReductionBaseTrans.validate(), psyclone.psyir.transformations.intrinsics.dotproduct2code_trans.DotProduct2CodeTrans.validate(), psyclone.psyir.transformations.intrinsics.intrinsic2code_trans.Intrinsic2CodeTrans.validate(), psyclone.psyir.transformations.intrinsics.matmul2code_trans.Matmul2CodeTrans.validate(), psyclone.psyir.transformations.loop_swap_trans.LoopSwapTrans.validate(), psyclone.psyir.transformations.loop_tiling_2d_trans.LoopTiling2DTrans.validate(), psyclone.psyir.transformations.loop_trans.LoopTrans.validate(), psyclone.psyir.transformations.omp_task_trans.OMPTaskTrans.validate(), psyclone.psyir.transformations.omp_taskwait_trans.OMPTaskwaitTrans.validate(), psyclone.psyir.transformations.parallel_loop_trans.ParallelLoopTrans.validate(), psyclone.psyir.transformations.reference2arrayrange_trans.Reference2ArrayRangeTrans.validate(), psyclone.psyir.transformations.replace_induction_variables_trans.ReplaceInductionVariablesTrans.validate(), psyclone.transformations.OMPDeclareTargetTrans.validate(), psyclone.transformations.DynamoOMPParallelLoopTrans.validate(), psyclone.transformations.Dynamo0p3OMPLoopTrans.validate(), psyclone.transformations.GOceanOMPLoopTrans.validate(), psyclone.transformations.Dynamo0p3RedundantComputationTrans.validate(), psyclone.transformations.Dynamo0p3KernelConstTrans.validate(), psyclone.transformations.ACCRoutineTrans.validate(), psyclone.transformations.KernelImportsToArguments.validate(), psyclone.domain.gocean.transformations.gocean_loop_fuse_trans.GOceanLoopFuseTrans.validate(), psyclone.domain.lfric.transformations.lfric_loop_fuse_trans.LFRicLoopFuseTrans.validate(), psyclone.psyir.transformations.loop_fuse_trans.LoopFuseTrans.validate(), psyclone.domain.gocean.transformations.gocean_extract_trans.GOceanExtractTrans.validate(), psyclone.domain.lfric.transformations.lfric_extract_trans.LFRicExtractTrans.validate(), psyclone.psyir.transformations.extract_trans.ExtractTrans.validate(), psyclone.psyir.transformations.nan_test_trans.NanTestTrans.validate(), psyclone.psyir.transformations.read_only_verify_trans.ReadOnlyVerifyTrans.validate(), psyclone.transformations.ParallelRegionTrans.validate(), psyclone.transformations.OMPParallelTrans.validate(), psyclone.transformations.ACCParallelTrans.validate(), psyclone.transformations.ACCKernelsTrans.validate(), psyclone.transformations.ACCDataTrans.validate(), psyclone.psyir.transformations.psy_data_trans.PSyDataTrans.validate(), psyclone.psyir.transformations.region_trans.RegionTrans.validate(), and psyclone.transformations.ACCEnterDataTrans.validate().

Here is the call graph for this function:

◆ name()

def psyclone.transformations.MoveTrans.name (   self)
 Returns the name of this transformation as a string.

Reimplemented from psyclone.psyGen.Transformation.

Definition at line 1692 of file transformations.py.

1692  def name(self):
1693  ''' Returns the name of this transformation as a string.'''
1694  return "Move"
1695 
Here is the caller graph for this function:

◆ validate()

def psyclone.transformations.MoveTrans.validate (   self,
  node,
  location,
  options = None 
)
 validity checks for input arguments.

:param node: the node to be moved.
:type node: :py:class:`psyclone.psyir.nodes.Node`
:param location: node before or after which the given node\
    should be moved.
:type location: :py:class:`psyclone.psyir.nodes.Node`
:param options: a dictionary with options for transformations.
:type options: Optional[Dict[str, Any]]
:param str options["position"]: either 'before' or 'after'.

:raises TransformationError: if the given node is not an instance \
    of :py:class:`psyclone.psyir.nodes.Node`
:raises TransformationError: if the location is not valid.

Definition at line 1696 of file transformations.py.

1696  def validate(self, node, location, options=None):
1697  # pylint: disable=arguments-differ
1698  ''' validity checks for input arguments.
1699 
1700  :param node: the node to be moved.
1701  :type node: :py:class:`psyclone.psyir.nodes.Node`
1702  :param location: node before or after which the given node\
1703  should be moved.
1704  :type location: :py:class:`psyclone.psyir.nodes.Node`
1705  :param options: a dictionary with options for transformations.
1706  :type options: Optional[Dict[str, Any]]
1707  :param str options["position"]: either 'before' or 'after'.
1708 
1709  :raises TransformationError: if the given node is not an instance \
1710  of :py:class:`psyclone.psyir.nodes.Node`
1711  :raises TransformationError: if the location is not valid.
1712  '''
1713 
1714  # Check that the first argument is a Node
1715  if not isinstance(node, Node):
1716  raise TransformationError(
1717  "In the Move transformation apply method the first argument "
1718  "is not a Node")
1719 
1720  # Check new location conforms to any data dependencies
1721  # This also checks the location and position arguments
1722  if not options:
1723  options = {}
1724  position = options.get("position", "before")
1725  if not node.is_valid_location(location, position=position):
1726  raise TransformationError(
1727  "In the Move transformation apply method, data dependencies "
1728  "forbid the move to the new location")
1729 
Here is the caller graph for this function:

The documentation for this class was generated from the following file: