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
Awith the sign ofBInheritance

- 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
AandBcould be arbitrarily complex PSyIR expressions,...could be arbitrary PSyIR code and whereABShas 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:
node (
psyclone.psyir.nodes.IntrinsicCall) – a SIGN IntrinsicCall node.symbol_table (
psyclone.psyir.symbols.SymbolTable) – the symbol table.options (Optional[Dict[str, Any]]) – a dictionary with options for transformations.
- validate(node, options=None, **kwargs)[source]#
Check that it is safe to apply the transformation to the supplied node.
- Parameters:
node (
psyclone.psyir.nodes.IntrinsicCall) – the SIGN call to transform.options (dict[str, Any]) – any options for the transformation.
symbol_table (
psyclone.psyir.symbols.SymbolTable) – the symbol table.