psyclone.psyir.transformations.intrinsics.abs2code_trans#

Module providing a transformation from a PSyIR ABS operator to PSyIR code. This could be useful if the ABS operator is not supported by the back-end or if the performance in the inline code is better than the intrinsic.

Classes#

  • Abs2CodeTrans: Provides a transformation from a PSyIR ABS Operator node to

class psyclone.psyir.transformations.intrinsics.abs2code_trans.Abs2CodeTrans[source]#

Provides a transformation from a PSyIR ABS Operator node to equivalent code in a PSyIR tree. Validity checks are also performed.

The transformation replaces

R = ABS(X)

with the following logic:

IF X < 0.0:
    R = X*-1.0
ELSE:
    R = X

Inheritance

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

Apply the ABS intrinsic conversion transformation to the specified node. This node must be an ABS UnaryOperation. The ABS UnaryOperation is converted to equivalent inline code. This is implemented as a PSyIR transform from:

R = ... ABS(X) ...

to:

tmp_abs = X
if tmp_abs < 0.0:
    res_abs = tmp_abs*-1.0
else:
    res_abs = tmp_abs
R = ... res_abs ...

where X could be an arbitrarily complex PSyIR expression and ... could be arbitrary PSyIR code.

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

Parameters:
validate(node, options=None)[source]#

Check that it is safe to apply the transformation to the supplied node.

Parameters: