psyclone.psyir.transformations.intrinsics.sign2code_trans#

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

Classes#

  • Sign2CodeTrans: Provides a transformation from a PSyIR SIGN intrinsic node to

class psyclone.psyir.transformations.intrinsics.sign2code_trans.Sign2CodeTrans[source]#

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

The transformation replaces

R = SIGN(A, B)

with the following logic:

R = ABS(A)
if B < 0.0:
    R = R*-1.0

i.e. the value of A with the sign of B

Inheritance

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

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

R = ... SIGN(A, B) ...

to:

tmp_abs = A
if tmp_abs < 0.0:
    res_abs = tmp_abs*-1.0
else:
    res_abs = tmp_abs
res_sign = res_abs
tmp_sign = B
if tmp_sign < 0.0:
    res_sign = res_sign*-1.0
R = ... res_sign ...

where A and B could be arbitrarily complex PSyIR expressions, ... could be arbitrary PSyIR code and where ABS has been replaced with inline code by the NemoAbsTrans transformation.

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

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

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

Parameters: