38 '''Module providing a transformation from a generic PSyIR representation of
39 a PSy layer into a NEMO-specific one.
46 CreateNemoInvokeScheduleTrans, \
52 Transform generic (language-level) PSyIR representation into a PSyclone
53 version with specialised, NEMO-specific nodes. For example:
55 >>> from psyclone.psyir.frontend.fortran import FortranReader
56 >>> from psyclone.psyir.nodes import Loop
57 >>> from psyclone.domain.nemo.transformations import CreateNemoPSyTrans
60 ... integer :: ji, tmp(10)
64 ... end subroutine sub'''
65 >>> psyir = FortranReader().psyir_from_source(code)
66 >>> loop = psyir.walk(Loop)[0]
67 >>> trans = CreateNemoPSyTrans()
68 >>> trans.apply(psyir)
69 >>> print(psyir.view(colour=False, indent=" "))
71 NemoInvokeSchedule[invoke='sub']
72 0: Loop[type='lon', field_space='None', it_space='None']
73 Literal[value:'1', Scalar<INTEGER, UNDEFINED>]
74 Literal[value:'10', Scalar<INTEGER, UNDEFINED>]
75 Literal[value:'1', Scalar<INTEGER, UNDEFINED>]
78 ArrayReference[name:'tmp']
80 BinaryOperation[operator:'MUL']
81 Literal[value:'2', Scalar<INTEGER, UNDEFINED>]
85 The result of this transformation is that the root `Routine` has
86 been converted into a `NemoInvokeSchedule`, the `Loop` is now a
87 `NemoLoop` (with type 'lon' [for longitude]) and the body of the loop
88 is now an `InlinedKern`.
94 :returns: the name of the transformation.
97 TODO #1214 remove this method.
100 return type(self).__name__
104 Check that the supplied node is a valid target for this transformation.
106 :param node: the root of the PSyIR tree to be transformed.
107 :type node: :py:class:`psyclone.psyir.nodes.Node`
108 :param options: a dictionary with options for \
109 transformations. No options are used in this \
110 transformation. This is an optional argument that defaults \
112 :type options: Optional[Dict[str, Any]]
114 :raises TransformationError: if the supplied node is not a PSyIR node.
117 if not isinstance(node, Node):
118 raise TransformationError(
119 f
"Error in CreateNemoPSyTrans transformation. The supplied "
120 f
"node should be a PSyIR Node but found "
121 f
"'{type(node).__name__}'")
123 super(CreateNemoPSyTrans, self).
validate(node, options=options)
125 def apply(self, psyir, options=None):
127 Takes generic PSyIR and replaces recognised structures with
128 NEMO-specific PSyIR (in-place). Note that this may mean replacing
129 the top-level node itself and therefore this routine returns the
130 root of the modified tree.
132 :param psyir: the root node of the PSyIR tree to process.
133 :type psyir: :py:class:`psyclone.psyir.nodes.Node`
134 :param options: a dictionary with options for \
135 transformations. No options are used in this \
136 transformation. This is an optional argument that defaults \
138 :type options: Optional[Dict[str, Any]]
141 self.
validatevalidate(psyir, options=options)
143 invoke_trans = CreateNemoInvokeScheduleTrans()
144 loop_trans = CreateNemoLoopTrans()
149 loops = psyir.walk(Loop)
156 loop_trans.apply(loop)
161 for routine
in psyir.walk(Routine):
162 invoke_trans.apply(routine)
166 __all__ = [
'CreateNemoPSyTrans']
def apply(self, psyir, options=None)
def validate(self, node, options=None)