Reference Guide  2.5.0
psyclone.psyir.nodes.reference.Reference Class Reference
Inheritance diagram for psyclone.psyir.nodes.reference.Reference:
Collaboration diagram for psyclone.psyir.nodes.reference.Reference:

Public Member Functions

def __init__ (self, symbol, **kwargs)
 
def __eq__ (self, other)
 
def is_array (self)
 
def symbol (self)
 
def symbol (self, symbol)
 
def name (self)
 
def node_str (self, colour=True)
 
def __str__ (self)
 
def get_signature_and_indices (self)
 
def reference_accesses (self, var_accesses)
 
def datatype (self)
 
def previous_access (self)
 
def next_access (self)
 
- Public Member Functions inherited from psyclone.psyir.nodes.node.Node
def __init__ (self, ast=None, children=None, parent=None, annotations=None)
 
def coloured_name (self, colour=True)
 
def ast (self)
 
def ast_end (self)
 
def ast (self, ast)
 
def ast_end (self, ast_end)
 
def annotations (self)
 
def dag (self, file_name='dag', file_format='svg')
 
def dag_gen (self, graph)
 
def dag_name (self)
 
def args (self)
 
def backward_dependence (self)
 
def forward_dependence (self)
 
def is_valid_location (self, new_node, position="before")
 
def depth (self)
 
def view (self, depth=0, colour=True, indent=" ", _index=None)
 
def addchild (self, child, index=None)
 
def children (self)
 
def children (self, my_children)
 
def parent (self)
 
def siblings (self)
 
def has_constructor_parent (self)
 
def position (self)
 
def abs_position (self)
 
def root (self)
 
def sameParent (self, node_2)
 
def walk (self, my_type, stop_type=None, depth=None)
 
def get_sibling_lists (self, my_type, stop_type=None)
 
def ancestor (self, my_type, excluding=None, include_self=False, limit=None, shared_with=None)
 
def kernels (self)
 
def following (self, routine=True)
 
def preceding (self, reverse=False, routine=True)
 
def immediately_precedes (self, node_2)
 
def immediately_follows (self, node_1)
 
def coded_kernels (self)
 
def loops (self)
 
def reductions (self, reprod=None)
 
def is_openmp_parallel (self)
 
def lower_to_language_level (self)
 
def scope (self)
 
def replace_with (self, node, keep_name_in_context=True)
 
def pop_all_children (self)
 
def detach (self)
 
def copy (self)
 
def validate_global_constraints (self)
 
def debug_string (self)
 
def origin_string (self)
 
def update_signal (self)
 
def path_from (self, ancestor)
 

Public Attributes

 symbol
 
- Public Attributes inherited from psyclone.psyir.nodes.node.Node
 position
 

Additional Inherited Members

- Static Public Attributes inherited from psyclone.psyir.nodes.node.Node
int START_DEPTH = 0
 
int START_POSITION = 0
 
 valid_annotations = tuple()
 

Detailed Description

Node representing a Reference Expression.

:param symbol: the symbol being referenced.
:type symbol: :py:class:`psyclone.psyir.symbols.Symbol`
:param kwargs: additional keyword arguments provided to the super class.
:type kwargs: unwrapped dict.

Definition at line 50 of file reference.py.

Member Function Documentation

◆ __eq__()

def psyclone.psyir.nodes.reference.Reference.__eq__ (   self,
  other 
)
Checks equivalence of two References. References are considered
equivalent if they are the same type of Reference and their symbol
name is the same.

:param object other: the object to check equality to.

:returns: whether other is equal to self.
:rtype: bool

Reimplemented from psyclone.psyir.nodes.node.Node.

Definition at line 69 of file reference.py.

69  def __eq__(self, other):
70  '''
71  Checks equivalence of two References. References are considered
72  equivalent if they are the same type of Reference and their symbol
73  name is the same.
74 
75  :param object other: the object to check equality to.
76 
77  :returns: whether other is equal to self.
78  :rtype: bool
79  '''
80  is_eq = super().__eq__(other)
81  # TODO #1698. Is reference equality enough comparing the symbols by
82  # name? (Currently it is needed because symbol equality is not fully
83  # implemented)
84  is_eq = is_eq and (self.symbol.name == other.symbol.name)
85  return is_eq
86 

References psyclone.psyir.nodes.reference.Reference.symbol.

◆ datatype()

def psyclone.psyir.nodes.reference.Reference.datatype (   self)
:returns: the datatype of this reference.
:rtype: :py:class:`psyclone.psyir.symbols.DataType`

Reimplemented from psyclone.psyir.nodes.datanode.DataNode.

Reimplemented in psyclone.psyir.nodes.structure_reference.StructureReference, and psyclone.psyir.nodes.array_reference.ArrayReference.

Definition at line 182 of file reference.py.

182  def datatype(self):
183  '''
184  :returns: the datatype of this reference.
185  :rtype: :py:class:`psyclone.psyir.symbols.DataType`
186 
187  '''
188  # pylint: disable=unidiomatic-typecheck
189  # Use type() directly as we need to ignore inheritance.
190  if type(self.symbol) is Symbol:
191  # We don't even have a DataSymbol
192  return UnresolvedType()
193  return self.symbol.datatype
194 

References psyclone.psyir.nodes.reference.Reference.symbol.

Here is the caller graph for this function:

◆ get_signature_and_indices()

def psyclone.psyir.nodes.reference.Reference.get_signature_and_indices (   self)
:returns: the Signature of this reference, and \
    an empty list of lists as 'indices' since this reference does \
    not represent an array access.
:rtype: tuple(:py:class:`psyclone.core.Signature`, list of \
    list of indices)

Reimplemented in psyclone.psyir.nodes.structure_reference.StructureReference.

Definition at line 146 of file reference.py.

146  def get_signature_and_indices(self):
147  ''':returns: the Signature of this reference, and \
148  an empty list of lists as 'indices' since this reference does \
149  not represent an array access.
150  :rtype: tuple(:py:class:`psyclone.core.Signature`, list of \
151  list of indices)
152  '''
153  return (Signature(self.name), [[]])
154 

References psyclone.domain.gocean.kernel.psyir.GOceanKernelMetadata.name, psyclone.domain.gocean.kernel.psyir.GOceanKernelMetadata.GridArg.name, psyclone.domain.gocean.transformations.gocean_const_loop_bounds_trans.GOConstLoopBoundsTrans.name(), psyclone.domain.gocean.transformations.gocean_move_iteration_boundaries_inside_kernel_trans.GOMoveIterationBoundariesInsideKernelTrans.name(), psyclone.domain.gocean.transformations.gocean_opencl_trans.GOOpenCLTrans.name(), psyclone.domain.lfric.kernel.lfric_kernel_metadata.LFRicKernelMetadata.name, psyclone.domain.nemo.transformations.create_nemo_invoke_schedule_trans.CreateNemoInvokeScheduleTrans.name(), psyclone.domain.nemo.transformations.create_nemo_psy_trans.CreateNemoPSyTrans.name(), psyclone.domain.nemo.transformations.nemo_allarrayrange2loop_trans.NemoAllArrayRange2LoopTrans.name(), psyclone.domain.nemo.transformations.nemo_arrayrange2loop_trans.NemoArrayRange2LoopTrans.name(), psyclone.domain.nemo.transformations.nemo_outerarrayrange2loop_trans.NemoOuterArrayRange2LoopTrans.name(), psyclone.dynamo0p3.DynamoPSy.name(), psyclone.expression.FunctionVar.name, psyclone.expression.NamedArg.name(), psyclone.gocean1p0.GOKernelGridArgument.name(), psyclone.gocean1p0.GOStencil.name(), psyclone.parse.algorithm.FileInfo.name(), psyclone.parse.algorithm.InvokeCall.name(), psyclone.parse.kernel.KernelProcedure.name(), psyclone.parse.kernel.KernelType.name(), psyclone.parse.module_info.ModuleInfo.name(), psyclone.psyad.transformations.assignment_trans.AssignmentTrans.name(), psyclone.psyGen.PSy.name(), psyclone.psyGen.Invoke.name(), psyclone.psyGen.Kern.name(), psyclone.psyGen.CodedKern.name, psyclone.psyGen.Argument.name(), psyclone.psyGen.Transformation.name(), psyclone.psyGen.DummyTransformation.name(), psyclone.psyir.nodes.container.Container.name, psyclone.psyir.nodes.member.Member.name, psyclone.psyir.nodes.reference.Reference.name(), psyclone.psyir.nodes.routine.Routine.name, psyclone.psyir.symbols.symbol.Symbol.name(), psyclone.psyir.transformations.allarrayaccess2loop_trans.AllArrayAccess2LoopTrans.name(), psyclone.psyir.transformations.arrayrange2loop_trans.ArrayRange2LoopTrans.name(), psyclone.psyir.transformations.fold_conditional_return_expressions_trans.FoldConditionalReturnExpressionsTrans.name(), psyclone.psyir.transformations.loop_trans.LoopTrans.name(), psyclone.psyir.transformations.omp_task_trans.OMPTaskTrans.name(), psyclone.psyir.transformations.psy_data_trans.PSyDataTrans.name(), psyclone.transformations.OMPSingleTrans.name(), psyclone.transformations.OMPMasterTrans.name(), psyclone.transformations.OMPParallelTrans.name(), psyclone.transformations.MoveTrans.name(), psyclone.transformations.Dynamo0p3AsyncHaloExchangeTrans.name(), psyclone.transformations.Dynamo0p3KernelConstTrans.name(), psyclone.transformations.ACCEnterDataTrans.name(), psyclone.transformations.ACCRoutineTrans.name(), psyclone.transformations.ACCKernelsTrans.name(), psyclone.transformations.ACCDataTrans.name(), and psyclone.transformations.KernelImportsToArguments.name().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_array()

def psyclone.psyir.nodes.reference.Reference.is_array (   self)
:returns: whether this reference is an array, False if it can not be
    determined.
:rtype: bool

Definition at line 88 of file reference.py.

88  def is_array(self):
89  '''
90  :returns: whether this reference is an array, False if it can not be
91  determined.
92  :rtype: bool
93 
94  '''
95  return self.symbol.is_array
96 

References psyclone.psyir.nodes.reference.Reference.symbol.

Here is the caller graph for this function:

◆ name()

def psyclone.psyir.nodes.reference.Reference.name (   self)
 Return the name of the referenced symbol.

:returns: Name of the referenced symbol.
:rtype: str

Definition at line 123 of file reference.py.

123  def name(self):
124  ''' Return the name of the referenced symbol.
125 
126  :returns: Name of the referenced symbol.
127  :rtype: str
128 
129  '''
130  return self._symbol.name
131 

References psyclone.psyir.nodes.reference.Reference._symbol.

Here is the caller graph for this function:

◆ next_access()

def psyclone.psyir.nodes.reference.Reference.next_access (   self)
:returns: the next reference to the same symbol.
:rtype: Optional[:py:class:`psyclone.psyir.nodes.Node`]

Definition at line 224 of file reference.py.

224  def next_access(self):
225  '''
226  :returns: the next reference to the same symbol.
227  :rtype: Optional[:py:class:`psyclone.psyir.nodes.Node`]
228  '''
229  # Avoid circular import
230  # pylint: disable=import-outside-toplevel
231  from psyclone.psyir.nodes.routine import Routine
232  # The scope is as far as the Routine that contains this
233  # Reference.
234  routine = self.ancestor(Routine)
235  # Handle the case when this is a subtree without an ancestor
236  # Routine
237  if routine is None:
238  routine = self.root
239  var_access = VariablesAccessInfo(nodes=routine)
240  signature, _ = self.get_signature_and_indices()
241  all_accesses = var_access[signature].all_accesses
242  index = len(all_accesses)
243  # Find my position in the VariablesAccesInfo
244  for i, access in enumerate(all_accesses):
245  if access.node is self:
246  index = i
247  break
248 
249  if len(all_accesses) > index+1:
250  return all_accesses[index+1].node
251  return None
252 
253 
254 # For AutoAPI documentation generation

References psyclone.psyir.nodes.node.Node.ancestor(), psyclone.psyir.nodes.array_mixin.ArrayMixin.get_signature_and_indices(), psyclone.psyir.nodes.array_of_structures_mixin.ArrayOfStructuresMixin.get_signature_and_indices(), psyclone.psyir.nodes.member.Member.get_signature_and_indices(), psyclone.psyir.nodes.reference.Reference.get_signature_and_indices(), psyclone.psyir.nodes.structure_member.StructureMember.get_signature_and_indices(), psyclone.psyir.nodes.structure_reference.StructureReference.get_signature_and_indices(), psyclone.f2pygen.BaseGen.root(), psyclone.f2pygen.BaseDeclGen.root(), and psyclone.psyir.nodes.node.Node.root().

Here is the call graph for this function:

◆ node_str()

def psyclone.psyir.nodes.reference.Reference.node_str (   self,
  colour = True 
)
 Create a text description of this node in the schedule, optionally
including control codes for colour.

:param bool colour: whether or not to include colour control codes.

:return: text description of this node.
:rtype: str

Reimplemented from psyclone.psyir.nodes.node.Node.

Definition at line 132 of file reference.py.

132  def node_str(self, colour=True):
133  ''' Create a text description of this node in the schedule, optionally
134  including control codes for colour.
135 
136  :param bool colour: whether or not to include colour control codes.
137 
138  :return: text description of this node.
139  :rtype: str
140  '''
141  return f"{self.coloured_name(colour)}[name:'{self.name}']"
142 

References psyclone.domain.common.algorithm.psyir.AlgorithmInvokeCall.node_str(), psyclone.domain.common.psylayer.psyloop.PSyLoop.node_str(), psyclone.domain.lfric.lfric_invoke_schedule.LFRicInvokeSchedule.node_str(), psyclone.domain.lfric.lfric_loop.LFRicLoop.node_str(), psyclone.dynamo0p3.LFRicHaloExchange.node_str(), psyclone.psyGen.InvokeSchedule.node_str(), psyclone.psyGen.GlobalSum.node_str(), psyclone.psyGen.HaloExchange.node_str(), psyclone.psyGen.Kern.node_str(), psyclone.psyGen.CodedKern.node_str(), psyclone.psyGen.InlinedKern.node_str(), psyclone.psyir.nodes.acc_directives.ACCLoopDirective.node_str(), psyclone.psyir.nodes.call.Call.node_str(), psyclone.psyir.nodes.codeblock.CodeBlock.node_str(), psyclone.psyir.nodes.container.Container.node_str(), psyclone.psyir.nodes.file_container.FileContainer.node_str(), psyclone.psyir.nodes.literal.Literal.node_str(), psyclone.psyir.nodes.loop.Loop.node_str(), psyclone.psyir.nodes.member.Member.node_str(), psyclone.psyir.nodes.node.Node.node_str(), psyclone.psyir.nodes.omp_clauses.OMPDefaultClause.node_str(), psyclone.psyir.nodes.omp_clauses.OMPScheduleClause.node_str(), psyclone.psyir.nodes.omp_clauses.OMPDependClause.node_str(), psyclone.psyir.nodes.omp_directives.OMPDoDirective.node_str(), psyclone.psyir.nodes.omp_directives.OMPLoopDirective.node_str(), psyclone.psyir.nodes.operation.Operation.node_str(), psyclone.psyir.nodes.reference.Reference.node_str(), and psyclone.psyir.nodes.routine.Routine.node_str().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ previous_access()

def psyclone.psyir.nodes.reference.Reference.previous_access (   self)
:returns: the previous reference to the same symbol.
:rtype: Optional[:py:class:`psyclone.psyir.nodes.Node`]

Definition at line 195 of file reference.py.

195  def previous_access(self):
196  '''
197  :returns: the previous reference to the same symbol.
198  :rtype: Optional[:py:class:`psyclone.psyir.nodes.Node`]
199  '''
200  # Avoid circular import
201  # pylint: disable=import-outside-toplevel
202  from psyclone.psyir.nodes.routine import Routine
203  # The scope is as far as the Routine that contains this
204  # Reference.
205  routine = self.ancestor(Routine)
206  # Handle the case when this is a subtree without an ancestor
207  # Routine
208  if routine is None:
209  routine = self.root
210  var_access = VariablesAccessInfo(nodes=routine)
211  signature, _ = self.get_signature_and_indices()
212  all_accesses = var_access[signature].all_accesses
213  index = -1
214  # Find my position in the VariablesAccesInfo
215  for i, access in enumerate(all_accesses):
216  if access.node is self:
217  index = i
218  break
219 
220  if index > 0:
221  return all_accesses[index-1].node
222  return None
223 

References psyclone.psyir.nodes.node.Node.ancestor(), psyclone.psyir.nodes.array_mixin.ArrayMixin.get_signature_and_indices(), psyclone.psyir.nodes.array_of_structures_mixin.ArrayOfStructuresMixin.get_signature_and_indices(), psyclone.psyir.nodes.member.Member.get_signature_and_indices(), psyclone.psyir.nodes.reference.Reference.get_signature_and_indices(), psyclone.psyir.nodes.structure_member.StructureMember.get_signature_and_indices(), psyclone.psyir.nodes.structure_reference.StructureReference.get_signature_and_indices(), psyclone.f2pygen.BaseGen.root(), psyclone.f2pygen.BaseDeclGen.root(), and psyclone.psyir.nodes.node.Node.root().

Here is the call graph for this function:

◆ reference_accesses()

def psyclone.psyir.nodes.reference.Reference.reference_accesses (   self,
  var_accesses 
)
Get all variable access information from this node, i.e.
it sets this variable to be read. It relies on
`get_signature_and_indices` and will correctly handle
array expressions.

:param var_accesses: VariablesAccessInfo instance that stores the \
    information about variable accesses.
:type var_accesses: \
    :py:class:`psyclone.core.VariablesAccessInfo`

Reimplemented from psyclone.psyir.nodes.node.Node.

Definition at line 155 of file reference.py.

155  def reference_accesses(self, var_accesses):
156  '''Get all variable access information from this node, i.e.
157  it sets this variable to be read. It relies on
158  `get_signature_and_indices` and will correctly handle
159  array expressions.
160 
161  :param var_accesses: VariablesAccessInfo instance that stores the \
162  information about variable accesses.
163  :type var_accesses: \
164  :py:class:`psyclone.core.VariablesAccessInfo`
165 
166  '''
167  sig, all_indices = self.get_signature_and_indices()
168  if self.symbol.is_import and \
169  var_accesses.options("USE-ORIGINAL-NAMES") and \
170  self.symbol.interface.orig_name:
171  # If the option is set to return the original (un-renamed)
172  # name of an imported symbol, get the original name from
173  # the interface and use it. The rest of the signature is
174  # used from the original access, it does not change.
175  sig = Signature(self.symbol.interface.orig_name, sig[1:])
176  for indices in all_indices:
177  for index in indices:
178  index.reference_accesses(var_accesses)
179  var_accesses.add_access(sig, AccessType.READ, self, all_indices)
180 

References psyclone.psyir.nodes.array_mixin.ArrayMixin.get_signature_and_indices(), psyclone.psyir.nodes.array_of_structures_mixin.ArrayOfStructuresMixin.get_signature_and_indices(), psyclone.psyir.nodes.member.Member.get_signature_and_indices(), psyclone.psyir.nodes.reference.Reference.get_signature_and_indices(), psyclone.psyir.nodes.structure_member.StructureMember.get_signature_and_indices(), psyclone.psyir.nodes.structure_reference.StructureReference.get_signature_and_indices(), and psyclone.psyir.nodes.reference.Reference.symbol.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ symbol() [1/2]

def psyclone.psyir.nodes.reference.Reference.symbol (   self)
 Return the referenced symbol.

:returns: the referenced symbol.
:rtype: :py:class:`psyclone.psyir.symbols.Symbol`

Definition at line 98 of file reference.py.

98  def symbol(self):
99  ''' Return the referenced symbol.
100 
101  :returns: the referenced symbol.
102  :rtype: :py:class:`psyclone.psyir.symbols.Symbol`
103 
104  '''
105  return self._symbol
106 

References psyclone.psyir.nodes.reference.Reference._symbol.

Here is the caller graph for this function:

◆ symbol() [2/2]

def psyclone.psyir.nodes.reference.Reference.symbol (   self,
  symbol 
)
:param symbol: the new symbol being referenced.
:type symbol: :py:class:`psyclone.psyir.symbols.Symbol`

:raises TypeError: if the symbol argument is not of type Symbol.

Definition at line 108 of file reference.py.

108  def symbol(self, symbol):
109  '''
110  :param symbol: the new symbol being referenced.
111  :type symbol: :py:class:`psyclone.psyir.symbols.Symbol`
112 
113  :raises TypeError: if the symbol argument is not of type Symbol.
114 
115  '''
116  if not isinstance(symbol, Symbol):
117  raise TypeError(
118  f"The {type(self).__name__} symbol setter expects a PSyIR "
119  f"Symbol object but found '{type(symbol).__name__}'.")
120  self._symbol = symbol
121 

References psyclone.psyir.nodes.reference.Reference._symbol.

Here is the caller graph for this function:

The documentation for this class was generated from the following file: