psyclone.psyir.transformations.fold_conditional_return_expressions_trans

This module contains the FoldConditionalReturnExpressionsTrans.

Classes

class psyclone.psyir.transformations.fold_conditional_return_expressions_trans.FoldConditionalReturnExpressionsTrans

Provides a transformation that folds conditional expressions with only a return statement inside so that the Return statement is moved to the end of the Routine and therefore it can be safely removed. This simplifies the control flow of the kernel to facilitate other transformations like kernel fusions. For example, the following code:

subroutine test(i)
    if (i < 5) then
        return
    endif
    if (i > 10) then
        return
    endif
    ! CODE
end subroutine

will be transformed to:

subroutine test(i)
    if (.not.(i < 5)) then
        if (.not.(i > 10)) then
            ! CODE
        endif
    endif
end subroutine

Inheritance

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

Apply this transformation to the supplied node.

Parameters:
  • node (psyclone.psyir.nodes.Routine) – the node to transform.

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

property name

Returns the name of this transformation as a string.

validate(node, options=None)

Ensure that it is valid to apply this transformation to the supplied node.

Parameters:
  • node (psyclone.psyir.nodes.Routine) – the node to validate.

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

Raises:

TransformationError – if the node is not a Routine.