38 Module providing a transformation from a generic PSyIR routine into a
49 Transform a generic PSyIR Routine into a NEMO InvokeSchedule.
52 >>> from psyclone.psyir.frontend.fortran import FortranReader
53 >>> from psyclone.psyir.nodes import Loop
54 >>> from psyclone.domain.nemo.transformations import \
55 CreateNemoInvokeScheduleTrans
63 ... end subroutine sub'''
64 >>> psyir = FortranReader().psyir_from_source(code)
65 >>> loop = psyir.walk(Loop)[0]
66 >>> trans = CreateNemoInvokeScheduleTrans()
67 >>> trans.apply(psyir.children[0])
68 >>> print(psyir.view(colour=False))
70 NemoInvokeSchedule[invoke='sub']
71 0: Loop[variable='ji']
72 Literal[value:'1', Scalar<INTEGER, UNDEFINED>]
73 Literal[value:'10', Scalar<INTEGER, UNDEFINED>]
74 Literal[value:'1', Scalar<INTEGER, UNDEFINED>]
77 ArrayReference[name:'tmp']
79 BinaryOperation[operator:'MUL']
80 Literal[value:'2.0', Scalar<REAL, UNDEFINED>]
84 The root node of this example has been transformed from a Routine into a
91 :returns: the name of the transformation.
94 TODO #1214 remove this method.
97 return type(self).__name__
101 Check that the supplied node is a valid target for this transformation.
103 :param node: the target of the transformation.
104 :type node: :py:class:`psyclone.psyir.nodes.Node`
105 :param options: a dictionary with options for \
106 transformations. No options are used in this \
107 transformation. This is an optional argument that defaults \
109 :type options: Optional[Dict[str, Any]]
111 :raises TransformationError: if the supplied node is not a Routine.
114 super(CreateNemoInvokeScheduleTrans, self).
validate(node,
117 if not isinstance(node, Routine):
118 raise TransformationError(
119 f
"Error in NemoInvokeTrans transformation. The supplied node "
120 f
"should be a PSyIR Routine but found '{type(node).__name__}'")
122 def apply(self, node, options=None):
124 Takes a generic PSyIR Routine and replaces it with a
125 NemoInvokeSchedule (in-place). Note that this may mean replacing
126 the top-level node itself and therefore this routine returns the
127 root of the modified tree.
129 :param node: the routine node to be transformed.
130 :type node: :py:class:`psyclone.psyir.nodes.Routine`
131 :param options: a dictionary with options for \
132 transformations. No options are used in this \
133 transformation. This is an optional argument that defaults \
135 :type options: Optional[Dict[str, Any]]
138 self.
validatevalidate(node, options=options)
142 return_symbol_name =
None
143 if node.return_symbol:
144 return_symbol_name = node.return_symbol.name
146 new_node = NemoInvokeSchedule.create(
147 node.name, node.symbol_table.detach(), node.pop_all_children(),
148 is_program=node.is_program,
149 return_symbol_name=return_symbol_name)
154 node.replace_with(new_node)
158 __all__ = [
'CreateNemoInvokeScheduleTrans']
def apply(self, node, options=None)
def validate(self, node, options=None)