psyclone.psyir.tools#
Tool module, containing all generic (API independent) tools.
Submodules#
Classes#
CallTreeUtils: This class provides functions to analyse the sequence ofDTCode: A simple enum to store the various info, warning and errorDependencyTools: This class provides some useful dependency tools, allowing a user toDefinitionUseChain: The DefinitionUseChain class is used to find nodes in a treeReadWriteInfo: This class stores signature and container name of variables read orReductionInferenceTool: Instances of this class are initialsied with a set of allowed
- class psyclone.psyir.tools.CallTreeUtils[source]#
This class provides functions to analyse the sequence of calls.
Inheritance

- get_in_out_parameters(node_list, collect_non_local_symbols=False, include_non_data_accesses=False)[source]#
Returns a ReadWriteInfo object that contains all variables that are input and output parameters to the specified node list. This function calls get_input_parameter and get_output_parameter, but avoids the repeated computation of the variable usage. If collect_non_local_symbols is set to True, the code will also include non-local symbols used directly or indirectly, i.e. it will follow the call tree as much as possible (e.g. it cannot resolve a procedure pointer, since then it is not known which function is actually called) and collect any other variables that will be read or written when executing the nodes specified in the node list. The corresponding module name for these variables will be included in the ReadWriteInfo result object. For this to work it is essential that the correct search paths are specified for the module manager.
- Parameters:
node_list (list[
psyclone.psyir.nodes.Node] |psyclone.psyir.nodes.Node) – list of PSyIR nodes to be analysed.collect_non_local_symbols (bool) – whether non-local symbols (i.e. symbols used in other modules either directly or indirectly) should be included in the in/out information.
- Returns:
a ReadWriteInfo object with the information about input- and output parameters.
- Return type:
- get_input_parameters(read_write_info, node_list, variables_info=None, include_non_data_accesses=False)[source]#
Adds all variables that are input parameters (i.e. are read before potentially being written) to the read_write_info object.
- Parameters:
read_write_info (
psyclone.psyir.tools.ReadWriteInfo) – this object stores the information about all input parameters.node_list (list[
psyclone.psyir.nodes.Node]) – list of PSyIR nodes to be analysed.variables_info (
psyclone.core.variables_info.VariablesAccessMap) – optional variable usage information, can be used to avoid repeatedly collecting this information.
- get_non_local_read_write_info(node_list, read_write_info)[source]#
Returns the information about non-local variables that are read or written.
- Parameters:
node_list (list[
psyclone.psyGen.Kern]) – list of nodes containing Kernel calls to interrogate.read_write_info (
psyclone.psyir.tools.ReadWriteInfo) – the object to update with the read/write information obtained.
- get_non_local_symbols(routine)[source]#
This function returns a list of non-local accesses in this routine. It returns a list of triplets, each one containing:
the type (‘routine’, ‘function’, ‘reference’, ‘unknown’). The latter is used for array references or function calls, which we cannot distinguish till #1314 is done.
the name of the module (lowercase). This can be ‘None’ if no module information is available.
the Signature of the symbol
the access information for the given variable
- Parameters:
routine (
psyclone.psyir.nodes.Routine) – the routine for which to collect all non-local accesses- Returns:
the non-local accesses in this routine.
- Return type:
list[tuple[str, str,
psyclone.core.Signature,psyclone.core.AccessSequence]]
- get_output_parameters(read_write_info, node_list, variables_info=None)[source]#
Adds all variables that are output parameters (i.e. are written) to the read_write_info object.
- Parameters:
read_write_info (
psyclone.psyir.tools.ReadWriteInfo) – this object stores the information about output parameters.node_list (list[
psyclone.psyir.nodes.Node]) – list of PSyIR nodes to be analysed.variables_info (Optional[
psyclone.core.variables_info.VariablesAccessMap]) – optional variable usage information, can be used to avoid repeatedly collecting this information.
- class psyclone.psyir.tools.DTCode(*values)[source]#
A simple enum to store the various info, warning and error codes used in the dependency analysis. It is based in IntEnum so the codes can be compared with the …_MIN and …_MAX values.
Inheritance

- class psyclone.psyir.tools.DependencyTools(loop_types_to_parallelise=None)[source]#
This class provides some useful dependency tools, allowing a user to overwrite/modify functions depending on the application. It includes a messaging system where functions can store messages that might be useful for the user to see.
- Parameters:
loop_types_to_parallelise (Optional[List[str]]) – A list of loop types that will be considered for parallelisation. An example loop type might be ‘lat’, indicating that only loops over latitudes should be parallelised. The actually supported list of loop types is specified in the PSyclone config file. This can be used to exclude for example 1-dimensional loops.
- Raises:
TypeError – if an invalid loop type is specified.
Inheritance

- can_loop_be_parallelised(loop, test_all_variables=False, signatures_to_ignore=None)[source]#
This function analyses a loop in the PsyIR to see if it can be safely parallelised.
- Parameters:
loop (
psyclone.psyir.nodes.Loop) – the loop node to be analysed.test_all_variables (bool) – if True, it will test if all variable accesses can be parallelised, otherwise it will stop after the first variable is found that can not be parallelised.
signatures_to_ignore (Optional[ List[
psyclone.core.Signature]]) – list of signatures for which to skip the access checks.
- Returns:
True if the loop can be parallelised.
- Return type:
bool
- Raises:
TypeError – if the supplied node is not a Loop.
- can_loops_be_fused(loop1, loop2)[source]#
Function that verifies if two loops can be fused.
- Parameters:
loop1 (
psyclone.psyir.nodes.Loop) – the first loop.loop2 (
psyclone.psyir.nodes.Loop) – the second loop.
- Returns:
whether the loops can be fused or not.
- Return type:
bool
- class psyclone.psyir.tools.DefinitionUseChain(reference, control_flow_region=None, start_point=None, stop_point=None)[source]#
The DefinitionUseChain class is used to find nodes in a tree that have data dependencies on the provided reference.
- Parameters:
reference (
psyclone.psyir.nodes.Reference) – The Reference for which the dependencies will be computed.control_flow_region (Optional[List[
psyclone.psyir.nodes.Node]]) – Optional region to search for data dependencies. Default is the parent Routine or the root of the tree’s children if no ancestor Routine exists.start_point (int) – Optional argument to define a start point for the dependency search.
stop_point (int) – Optional argument to define a stop point for the dependency search.
- Raises:
TypeError – If one of the arguments is the wrong type.
Inheritance

- property defsout#
- Returns:
the list of nodes that reach the end of the block without being killed, and therefore can have dependencies outside of this block.
- Return type:
- find_backward_accesses()[source]#
Find all the backward accesses for the reference defined in this DefinitionUseChain. Backward accesses are all of the prior References or Calls that read or write to the symbol of the reference up to the point that a write to the symbol is guaranteed to occur. DUC assumes that any control flow might not be taken, so writes that occur inside control flow do not end the backward access chain.
- Returns:
the backward accesses of the reference given to this DefinitionUseChain
- Return type:
- find_forward_accesses()[source]#
Find all the forward accesses for the reference defined in this DefinitionUseChain. Forward accesses are all of the References or Calls that read or write to the symbol of the reference up to the point that a write to the symbol is guaranteed to occur. PSyclone assumes all control flow may not be taken, so writes that occur inside control flow do not end the forward access chain.
- Returns:
the forward accesses of the reference given to this DefinitionUseChain
- Return type:
- property is_basic_block#
- Returns:
whether the scope of this DefinitionUseChain is a basic block, i.e. whether it contains any control flow nodes.
- Return type:
bool
- property killed#
- Returns:
the list of nodes that represent the last use of an assigned variable. Calling next_access on any of these nodes will find a write that reassigns it’s value.
- Return type:
- property uses#
- Returns:
the list of nodes using the value that the referenced symbol has before it is reassigned.
- Return type:
- class psyclone.psyir.tools.ReadWriteInfo[source]#
This class stores signature and container name of variables read or written. The container name is optional, it will default to “” if the signature belongs to a symbol declared in the local scope, otherwise it is the name of the container from which it must be imported.
The information is stored in lists of tuples, the first element being the container name, the second the signature. When accessing any of these two lists, the getter will make sure that the lists are sorted. This will guarantee that, for example, the kernel extraction and driver creation read the variables in the same order.
Inheritance

- add_read(signature, container_name=None)[source]#
This function adds a read access to the specified signature and container name. The container_name is optional and defaults to “”, indicating that this signature is not based on importing a symbol from an external container (i.e. a module in Fortran).
- Parameters:
signature (
psyclone.core.Signature) – the signature of the access.container_name (Optional[str]) – the container name (optional)
- add_write(signature, container_name=None)[source]#
This function adds a write access to the specified signature and container name. The container_name is optional and defaults to “”, indicating that this signature is not based on importing a symbol from an external container (i.e. a module in Fortran).
- Parameters:
signature (
psyclone.core.Signature) – the signature of the access.container_name (Optional[str]) – the container name (optional)
- property all_used_vars_list#
- Returns:
the sorted list of container_name,signature pairs that are used.
- Return type:
List[Tuple[str,:py:class:psyclone.core.Signature]]
- is_read(signature)[source]#
- Returns:
whether the signature is in the read list (independent of the container name).
- Return type:
bool
- property read_list#
- Returns:
the sorted list of container_name,signature pairs that are read.
- Return type:
List[Tuple[str,:py:class:psyclone.core.Signature]]
- property signatures_read#
- Returns:
the list of all signatures read.
- Return type:
List[
psyclone.core.Signature]
- property signatures_written#
- Returns:
the list of all signatures written.
- Return type:
List[
psyclone.core.Signature]
- property write_list#
- Returns:
the sorted list of container_name,signature pairs that are written.
- Return type:
List[Tuple[str,:py:class:psyclone.core.Signature]]
- class psyclone.psyir.tools.ReductionInferenceTool(red_ops=[])[source]#
Instances of this class are initialsied with a set of allowed reduction operators. When inferring reduction clauses, only reductions involving these operators are considered.
- Parameters:
red_ops (
List[Union[Operator,Intrinsic]]) – a list of allowed reduction operators.
Inheritance

- attempt_reduction(sig, access_seq)[source]#
Determine if the variable with the given Signature and AccessSequence can be handled using a reduction clause and, if so, return that clause. Otherwise, return None.
- Parameters:
sig (
Signature) – the variable being considered as a reduction variable.access_seq (
AccessSequence) – the access sequence for that variable.
- Return type:
- Returns:
the operator/reference pair that can be used for the reduction if reduction is possible, or None otherwise.