39 Module providing a transformation from a generic PSyIR Loop into a
50 Transform a generic PSyIR Loop into a NemoLoop. For example:
52 >>> from psyclone.psyir.frontend.fortran import FortranReader
53 >>> from psyclone.psyir.nodes import Loop
54 >>> from psyclone.domain.nemo.transformations import CreateNemoLoopTrans
57 ... integer :: ji, tmp(10)
61 ... end subroutine sub'''
62 >>> psyir = FortranReader().psyir_from_source(code)
63 >>> loops = psyir.walk(Loop)
64 >>> trans = CreateNemoLoopTrans()
65 >>> trans.apply(loops[0])
66 >>> print(psyir.view(colour=False))
69 0: Loop[type='lon', field_space='None', it_space='None']
70 Literal[value:'1', Scalar<INTEGER, UNDEFINED>]
71 Literal[value:'10', Scalar<INTEGER, UNDEFINED>]
72 Literal[value:'1', Scalar<INTEGER, UNDEFINED>]
75 ArrayReference[name:'tmp']
77 BinaryOperation[operator:'MUL']
78 Literal[value:'2', Scalar<INTEGER, UNDEFINED>]
82 As shown above, the resulting Schedule now contains a NemoLoop, indicated
83 by the "type='lon'" (for 'longitude') annotation for the Loop node.
89 :returns: the name of the transformation.
92 TODO #1214 remove this method.
95 return type(self).__name__
99 Check that the supplied node is a valid target for this transformation.
101 :param node: the target of the transformation.
102 :type node: :py:class:`psyclone.psyir.nodes.Node`
103 :param options: a dictionary with options for \
104 transformations. No options are used in this \
105 transformation. This is an optional argument that defaults \
107 :type options: Optional[Dict[str, Any]]
109 :raises TransformationError: if the supplied node is not a Routine.
112 super(CreateNemoLoopTrans, self).
validate(node, options=options)
114 if not isinstance(node, Loop):
115 raise TransformationError(
116 f
"Error in CreateNemoLoopTrans transformation. The supplied "
117 f
"node should be a PSyIR Loop but found "
118 f
"'{type(node).__name__}'")
120 def apply(self, loop, options=None):
122 Takes a generic PSyIR Loop node and replaces it with a NemoLoop.
124 :param loop: the Loop node to be transformed.
125 :type loop: :py:class:`psyclone.psyir.nodes.Loop`
126 :param options: a dictionary with options for \
127 transformations. No options are used in this \
128 transformation. This is an optional argument that defaults \
130 :type options: Optional[Dict[str, Any]]
133 self.
validatevalidate(loop, options=options)
137 table = loop.loop_body.symbol_table.detach()
138 nodes = loop.pop_all_children()
139 new_loop = NemoLoop.create(loop.variable,
140 nodes[0], nodes[1], nodes[2],
141 nodes[3].pop_all_children())
144 new_loop.loop_body.symbol_table.detach()
145 table.attach(new_loop.loop_body)
147 loop.replace_with(new_loop)
151 __all__ = [
'CreateNemoLoopTrans']
def validate(self, node, options=None)
def apply(self, loop, options=None)