psyclone.core.single_variable_access_info
This module provides management of variable access information.
Classes
AccessInfo
: This class stores information about a single accessSingleVariableAccessInfo
: This class stores a list with all accesses to one variable.
- class psyclone.core.single_variable_access_info.AccessInfo(access_type, location, node, component_indices=None)
This class stores information about a single access pattern of one variable (e.g. variable is read at a certain location). A location is a number which can be used to compare different accesses (i.e. if one access happens before another). Each consecutive location will have an increasing location number, but read and write accesses in the same statement will have the same location number. If the variable accessed is an array, this class will also store the indices used in the access. Note that the name of the variable is not stored in this class. It is a helper class used in the SingleVariableAccessInfo class, which stores all AccessInfo objects for a variable, and it stores the name of the variable.
- Parameters:
access – the access type.
location (int) – a number used in ordering the accesses.
node (
psyclone.psyir.nodes.Node
) – Node in PSyIR in which the access happens.component_indices (None, [], a list or a list of lists of
psyclone.psyir.nodes.Node
objects, or an object of typepsyclone.core.component_indices.ComponentIndices
) – indices used in the access, defaults to None.
Inheritance
- property access_type
- Returns:
the access type.
- Return type:
- change_read_to_write()
This changes the access mode from READ to WRITE. This is used for processing assignment statements, where the LHS is first considered to be READ, and which is then changed to be WRITE.
- Raises:
InternalError – if the variable originally does not have READ access.
- property component_indices
This function returns the list of accesses used for each component as an instance of ComponentIndices. For example, a(i)%b(j,k)%c will return an instance of ComponentIndices representing [ [i], [j, k], [] ]. In the case of a simple scalar variable such as a, the component_indices will represent [ [] ].
- Returns:
the indices used in this access for each component.
- Return type:
- is_array()
Test if any of the components has an index. E.g. an access like a(i)%b would still be considered an array.
- Returns:
if any of the variable components uses an index, i.e. the variable is an array.
- Return type:
bool
- property location
- Returns:
the location information for this access. Please see the Developers’ Guide for more information.
- Return type:
int
- property node
- Returns:
the PSyIR node at which this access happens.
- Return type:
- class psyclone.core.single_variable_access_info.SingleVariableAccessInfo(signature)
This class stores a list with all accesses to one variable.
- Parameters:
signature (
psyclone.core.Signature
) – signature of the variable.
Inheritance
- add_access_with_location(access_type, location, node, component_indices)
Adds access information to this variable.
- Parameters:
access_type (
psyclone.core.access_type.AccessType
) – the type of access (READ, WRITE, ….)location (int) – location information
node (
psyclone.psyir.nodes.Node
) – Node in PSyIR in which the access happens.component_indices (
psyclone.core.component_indices.ComponentIndices
) – indices used for each component of the access.
- property all_accesses
- Returns:
a list with all AccessInfo data for this variable.
- Return type:
List[
psyclone.core.AccessInfo
]
- property all_read_accesses
- Returns:
a list with all AccessInfo data for this variable that involve reading this variable.
- Return type:
List[
psyclone.core.AccessInfo
]
- property all_write_accesses
- Returns:
a list with all AccessInfo data for this variable that involve writing this variable.
- Return type:
List[
psyclone.core.AccessInfo
]
- change_read_to_write()
This function is only used when analysing an assignment statement. The LHS has first all variables identified, which will be READ. This function is then called to change the assigned-to variable on the LHS to from READ to WRITE. Since the LHS is stored in a separate SingleVariableAccessInfo class, it is guaranteed that there is only one entry for the variable.
- has_read_write()
Checks if this variable has at least one READWRITE access.
- Returns:
True if this variable is read (at least once).
- Return type:
bool
- is_accessed_before(reference)
Returns True if this variable is accessed before the specified reference, and False if not. This is equivalent to testing that ‘reference’ is the very first access, but this function will also verify that ‘reference’ is indeed in the list of accesses.
- Parameters:
reference (
psyclone.psyir.nodes.Reference
) – the reference at which to stop for access checks.- Returns:
True if this variable is read before the specified reference, and False if not.
- Return type:
bool
- Raises:
ValueError – if the specified reference is not in the list of all accesses.
- is_array(index_variable=None)
Checks if the variable is used as an array, i.e. if it has an index expression. If the optional index_variable is specified, this variable must be used in (at least one) index access in order for this variable to be considered as an array.
- Parameters:
index_variable (str) – only considers this variable to be used as array if there is at least one access using this index_variable.
- Returns:
true if there is at least one access to this variable that uses an index.
- Return type:
bool
- is_read()
- Returns:
True if this variable is read (at least once).
- Return type:
bool
- is_read_before(reference)
Returns True if this variable is read before the specified reference, and False if not.
- Parameters:
reference (
psyclone.psyir.nodes.Reference
) – the reference at which to stop for access checks.- Returns:
True if this variable is read before the specified reference, and False if not.
- Return type:
bool
- Raises:
ValueError – if the specified reference is not in the list of all accesses.
- is_read_only()
Checks if this variable is always read, and never written.
- Returns:
True if this variable is read only.
- Return type:
bool
- is_written()
- Returns:
True if this variable is written (at least once).
- Return type:
bool
- is_written_before(reference)
Returns True if this variable is written before the specified reference, and False if not.
- Parameters:
reference (
psyclone.psyir.nodes.Reference
) – the reference at which to stop for access checks.- Returns:
True if this variable is written before the specified reference, and False if not.
- Return type:
bool
- Raises:
ValueError – if the specified reference is not in the list of all accesses.
- is_written_first()
- Returns:
True if this variable is written in the first access (which indicates that this variable is not an input variable for a kernel).
- Return type:
bool
- property signature
- Returns:
the signature for which the accesses are stored.
- Return type:
- property var_name
- Returns:
the name of the variable whose access info is managed.
- Return type:
str