psyclone.core.variables_access_info
This module provides management of variable access information.
Classes
VariablesAccessInfo
: This class stores all SingleVariableAccessInfo instances for all
- class psyclone.core.variables_access_info.VariablesAccessInfo(nodes=None, options=None)
This class stores all SingleVariableAccessInfo instances for all variables in the corresponding code section. It maintains ‘location’ information, which is an integer number that is increased for each new statement. It can be used to easily determine if one access is before another.
- Parameters:
nodes (Optional[
psyclone.psyir.nodes.Node
| List[psyclone.psyir.nodes.Node
]]) – optional, a single PSyIR node or list of nodes from which to initialise this object.options (Dict[str, Any]) – a dictionary with options to influence which variable accesses are to be collected.
options["COLLECT-ARRAY-SHAPE-READS"] (Any) – if this option is set to a True value, arrays used as first parameter to the PSyIR query operators lbound, ubound, or size will be reported as ‘read’. Otherwise, these accesses will be ignored.
options["USE-ORIGINAL-NAMES"] (Any) – if this option is set to a True value, an imported symbol that is renamed (
use mod, a=>b
) will be reported using the original name (b
in the example). Otherwise these symbols will be reported using the renamed name (a
).
- Raises:
InternalError – if the optional options parameter is not a dictionary.
InternalError – if the nodes parameter either is a list and contains an element that is not a
psyclone.psyir.nodes.Node
, of if nodes is not a list and is not of typepsyclone.psyir.nodes.Node
Inheritance
- add_access(signature, access_type, node, component_indices=None)
Adds access information for the variable with the given signature. If the component_indices parameter is not an instance of ComponentIndices, it is used to construct an instance. Therefore it can be None, a list or a list of lists of PSyIR nodes. In the case of a list of lists, this will be used unmodified to construct the ComponentIndices structures. If it is a simple list, it is assumed that it contains the indices used in accessing the last component of the signature. For example, for a%b with component_indices=[i,j], it will create [[], [i,j] as component indices, indicating that no index is used in the first component a. If the access is supposed to be for a(i)%b(j), then the component_indices argument must be specified as a list of lists, i.e. [[i], [j]].
- Parameters:
signature (
psyclone.core.Signature
) – the signature of the variable.access_type (
psyclone.core.access_type.AccessType
) – the type of access (READ, WRITE, …)node (
psyclone.psyir.nodes.Node
instance) – Node in PSyIR in which the access happens.component_indices (
psyclone.core.component_indices.ComponentIndices
, or any other type that can be used to construct a ComponentIndices instance (None, List[psyclone.psyir.nodes.Node
] or List[List[psyclone.psyir.nodes.Node
]])) – index information for the access.
- property all_signatures
- Returns:
all signatures contained in this instance, sorted (in order to make test results reproducible).
- Return type:
List[
psyclone.core.signature
]
- has_read_write(signature)
Checks if the specified variable signature has at least one READWRITE access (which is typically only used in a function call).
- Parameters:
signature (
psyclone.core.Signature
) – signature of the variable- Returns:
True if the specified variable name has (at least one) READWRITE access.
- Return type:
bool
- Raises:
KeyError if the signature cannot be found.
- is_read(signature)
Checks if the specified variable signature is at least read once.
- Parameters:
signature (
psyclone.core.Signature
) – signature of the variable- Returns:
True if the specified variable name is read (at least once).
- Return type:
bool
- Raises:
KeyError if the signature cannot be found.
- is_written(signature)
Checks if the specified variable signature is at least written once.
- Parameters:
signature (
psyclone.core.Signature
) – signature of the variable.- Returns:
True if the specified variable is written (at least once).
- Return type:
bool
- Raises:
KeyError if the signature name cannot be found.
- property location
Returns the current location of this instance, which is the location at which the next accesses will be stored. See the Developers’ Guide for more information.
- Returns:
the current location of this object.
- Return type:
int
- merge(other_access_info)
Merges data from a VariablesAccessInfo instance to the information in this instance.
- Parameters:
other_access_info (
psyclone.core.VariablesAccessInfo
) – the other VariablesAccessInfo instance.
- next_location()
Increases the location number.
- options(key=None)
Returns the value of the options for a specified key, or None if the key is not specified in the options. If no key is specified, the whole option dictionary is returned.
- Parameters:
key (Optional[str]) – the option to query, or None if all options should be returned.
- Returns:
the value of the option associated with the provided key or the whole option dictionary if it is not supplied.
- Return type:
Union[None, Any, dict]
- Raises:
InternalError – if an invalid key is specified.