psyclone.psyir.nodes.reference#

This module contains the implementation of the Reference node.

Classes#

  • Reference: Node representing a Reference Expression.

class psyclone.psyir.nodes.reference.Reference(symbol, **kwargs)[source]#

Node representing a Reference Expression.

Parameters:
  • symbol (psyclone.psyir.symbols.Symbol) – the symbol being referenced.

  • kwargs (unwrapped dict.) – additional keyword arguments provided to the super class.

Inheritance

Inheritance diagram of Reference
property datatype#
Returns:

the datatype of this reference.

Return type:

psyclone.psyir.symbols.DataType

enters_scope(scope, visited_nodes=None)[source]#

Whether the symbol lifetime starts before the given scope. For example, given the following fortran code:

do i=1,10
  a = 1
  if (b>3) c = 1
end do

‘a’ does not enter the scope. Even if it had a value before in the loop scope this is reassigned to a new value. However, ‘b’ and ‘c’ values enter the scope, because there is a path in which they take the value the symbol had before the scope.

Parameters:
  • scope (Node) – the given scope that we evaluate.

  • visited_nodes (Optional[set]) – a set of nodes already visited, this is necessary because the dependency chains may contain cycles. Defaults to an empty set.

Return type:

bool

Returns:

whether the symbol lifetime starts before the given scope.

escapes_scope(scope, visited_nodes=None)[source]#

Whether the symbol lifetime continues after the given scope. For example, given the following fortran code:

    do i=1,10
      a = 1
      b = 2
      c = 3
    end do
    b = 4
    call mysub(a, b)
end subroutine

‘b’ and ‘c’ if it is local, finish their value lifetime at the end of the loop scope (it is not re-used afterwards). While for ‘a’ and ‘c’ if it is global, their value may be used later and they “escape the scope”.

Parameters:
  • scope (Node) – the given scope that we evaluate.

  • visited_nodes (Optional[set]) – a set of nodes already visited, this is necessary because the dependency chains may contain cycles. Defaults to an empty set.

Return type:

bool

Returns:

whether the symbol lifetime continues after the given scope.

get_all_accessed_symbols()[source]#
Return type:

set[Symbol]

Returns:

a set of all the symbols accessed inside this Reference.

get_signature_and_indices()[source]#
Returns:

the Signature of this reference, and an empty list of lists as ‘indices’ since this reference does not represent an array access.

Return type:

tuple(psyclone.core.Signature, list of list of indices)

property is_read#
Returns:

whether this reference is reading from its symbol.

Return type:

bool

property is_write#
Returns:

whether this reference is writing to its symbol.

Return type:

bool

property name#

Return the name of the referenced symbol.

Returns:

Name of the referenced symbol.

Return type:

str

next_accesses()[source]#
Returns:

the nodes accessing the same symbol directly after this reference. It can be multiple nodes if the control flow diverges and there are multiple possible accesses.

Return type:

List[psyclone.psyir.nodes.Node]

node_str(colour=True)[source]#

Create a text description of this node in the schedule, optionally including control codes for colour.

Parameters:

colour (bool) – whether or not to include colour control codes.

Returns:

text description of this node.

Return type:

str

previous_accesses()[source]#
Returns:

the nodes accessing the same symbol directly before this reference. It can be multiple nodes if the control flow diverges and there are multiple possible accesses.

Return type:

List[psyclone.psyir.nodes.Node]

reference_accesses()[source]#
Return type:

VariablesAccessMap

Returns:

a map of all the symbol accessed inside this node, the keys are Signatures (unique identifiers to a symbol and its structure acccessors) and the values are AccessSequence (a sequence of AccessTypes).

replace_symbols_using(table_or_symbol)[source]#

Update any Symbols referenced by this Node with those in the supplied table (or just the supplied Symbol instance) if they have matching names. If there is no match for a given Symbol then it is left unchanged.

Parameters:

table_or_symbol (psyclone.psyir.symbols.SymbolTable | psyclone.psyir.symbols.Symbol) – the symbol table from which to get replacement symbols or a single, replacement Symbol.

property symbol#

Return the referenced symbol.

Returns:

the referenced symbol.

Return type:

psyclone.psyir.symbols.Symbol