psyclone.psyir.transformations.intrinsics.minormax2code_trans#

Module containing a class that provides functionality to transform a PSyIR MIN or MAX intrinsics to PSyIR code. This could be useful if the intrinsic is not supported by the back-end or if the performance of the inline code is better than the intrinsic. This utility transformation should not be called directly by the user, rather it provides functionality that can be specialised by MIN and MAX-specific transformations.

Classes#

class psyclone.psyir.transformations.intrinsics.minormax2code_trans.MinOrMax2CodeTrans[source]#

Provides a utility transformation from a PSyIR MIN or MAX Intrinsic node to equivalent code in a PSyIR tree. Validity checks are also performed (by the parent class). This utility transformation is not designed to be called directly by the user, rather it should be specialised to provide MIN or MAX transformations.

The transformation replaces

R = [MIN or MAX](A, B, C ...)

with the following logic:

R = A
if B [< or >] R:
    R = B
if C [< or >] R:
    R = C
...

Inheritance

Inheritance diagram of MinOrMax2CodeTrans
apply(node, options=None, **kwargs)[source]#

Apply this utility transformation to the specified node. This node must be a MIN or MAX IntrinsicCall. The intrinsic is converted to equivalent inline code. This is implemented as a PSyIR transform from:

R = ... [MIN or MAX](A, B, C ...) ...

to:

res = A
tmp = B
IF tmp [< or >] res:
    res = tmp
tmp = C
IF tmp [< or >] res:
    res = tmp
...
R = ... res ...

where A, B, C … could be arbitrarily complex PSyIR expressions and the ... before and after [MIN or MAX](A, B, C ...) can be arbitrary PSyIR code.

This transformation requires the IntrinsicCall node to be a descendant of an assignment and will raise an exception if this is not the case.

Parameters: