psyclone.psyir.nodes#

PSyIR nodes package module

Submodules#

Functions#

psyclone.psyir.nodes.colored(text, color=None, on_color=None, attrs=None, *, no_color=None, force_color=None)[source]#

Colorize text.

Return type:

str

Available text colors:

black, red, green, yellow, blue, magenta, cyan, white, light_grey, dark_grey, light_red, light_green, light_yellow, light_blue, light_magenta, light_cyan.

Available text highlights:

on_black, on_red, on_green, on_yellow, on_blue, on_magenta, on_cyan, on_white, on_light_grey, on_dark_grey, on_light_red, on_light_green, on_light_yellow, on_light_blue, on_light_magenta, on_light_cyan.

Alternatively, both text colors (color) and highlights (on_color) may be specified via a tuple of 0-255 ints (R, G, B).

Available attributes:

bold, dark, underline, blink, reverse, concealed.

Example:

colored(‘Hello, World!’, ‘red’, ‘on_black’, [‘bold’, ‘blink’]) colored(‘Hello, World!’, ‘green’) colored(‘Hello, World!’, (255, 0, 255)) # Purple

Classes#

  • ArrayMember: Node representing an access to the element(s) of an array that is a

  • ArrayReference: Node representing a reference to an element or elements of an Array.

  • ArrayOfStructuresMember: Node representing a membership expression of a parent structure where the

  • ArrayOfStructuresReference: Node representing an access to a member of one or more elements of an

  • Assignment: Node representing an Assignment statement. As such it has a LHS and RHS

  • AtomicDirectiveType: Enumeration of the available atomic operation types supported by

  • AtomicDirectiveMixin: A mixin class for directives implementing atomic behaviour.

  • BinaryOperation: Node representing a BinaryOperation expression. As such it has two operands

  • Call: Node representing a Call. This can be found as a standalone statement

  • Clause: Base abstract class for all clauses.

  • CodeBlock: Node representing some generic Fortran code that PSyclone does not

  • Container: Node representing a set of Routine and/or Container nodes, as well

  • DataNode: Abstract node representing a general PSyIR expression that represents a

  • FileContainer: PSyIR node to encapsulate the scope of a source file. In the

  • IfBlock: Node representing an if-block within the PSyIR. It has two mandatory

  • IntrinsicCall: Node representing a call to an intrinsic routine (function or

  • Literal: Node representing a Literal. The value and datatype properties of

  • Loop: Node representing a loop within the PSyIR. It has 4 mandatory children:

  • Member: Node representing a membership expression of a structure.

  • Node: Base class for a PSyIR node.

  • OperatorClause: Base abstract class for all clauses that have an operator.

  • Operation: Abstract base class for PSyIR nodes representing operators.

  • Range: The Range node is used to capture a range of integers via

  • Reference: Node representing a Reference Expression.

  • Return: Node representing a Return statement (subroutine break without return

  • Routine: A sub-class of a Schedule that represents a subroutine, function or

  • Schedule: Stores schedule information for a sequence of statements (supplied

  • Statement: Abstract node representing a general PSyIR Statement.

  • StructureMember: Node representing a membership expression of the parent’s Reference that

  • StructureReference: Node representing a reference to a component of a structure. As such

  • UnaryOperation: Node representing a UnaryOperation expression. As such it has one operand

  • ScopingNode: Abstract node that has an associated Symbol Table to keep track of

  • WhileLoop: Node representing a while loop within the PSyIR. It has two mandatory

  • KernelSchedule: A KernelSchedule is the parent node of the PSyIR for Kernel source code.

  • PSyDataNode: This class can be inserted into a schedule to instrument a set of nodes.

  • ExtractNode: This class can be inserted into a Schedule to mark Nodes for

  • ProfileNode: This class can be inserted into a schedule to create profiling code.

  • ReadOnlyVerifyNode: This class can be inserted into a Schedule to mark Nodes for

  • ValueRangeCheckNode: This class can be inserted into a Schedule to mark Nodes for

  • Directive: Abstract base class for all Directive statements.

  • RegionDirective: Base class for all Directive nodes that have an associated

  • StandaloneDirective: Base class for all StandaloneDirective statements. This class is

  • ACCAtomicDirective: OpenACC directive to represent that the memory accesses in the associated

  • ACCDirective: Base mixin class for all OpenACC directive statements.

  • ACCRegionDirective: Base class for all OpenACC region directive statements.

  • ACCStandaloneDirective: Base class for all standalone OpenACC directive statements.

  • ACCDataDirective: Class representing the !$ACC DATA … !$ACC END DATA directive

  • ACCEnterDataDirective: Class representing a “!$ACC enter data” OpenACC directive in

  • ACCParallelDirective: Class representing the !$ACC PARALLEL directive of OpenACC

  • ACCLoopDirective: Class managing the creation of a ‘!$acc loop’ OpenACC directive.

  • ACCKernelsDirective: Class representing the !$ACC KERNELS directive in the PSyIR.

  • ACCUpdateDirective: Class representing the OpenACC update directive in the PSyIR. It has

  • ACCRoutineDirective: Class representing an “ACC routine” OpenACC directive in PSyIR.

  • ACCCopyClause: OpenACC copy clause. Specifies a list of variables that are to be copied

  • ACCCopyInClause: OpenACC copy clause. Specifies a list of variables that are to be copied

  • ACCCopyOutClause: OpenACC copy clause. Specifies a list of variables that are to be copied

  • OMPAtomicDirective: OpenMP directive to represent that the memory accesses in the associated

  • OMPBarrierDirective: Class representing an OpenMP BARRIER directive in the PSyIR.

  • OMPDirective: Base mixin class for all OpenMP-related directives.

  • OMPRegionDirective: Base class for all OpenMP region-related directives.

  • OMPStandaloneDirective: Base class for all OpenMP-related standalone directives.

  • OMPParallelDirective: Class representing an OpenMP Parallel directive.

  • OMPSerialDirective: Abstract class representing OpenMP serial regions, e.g.

  • OMPSingleDirective: Class representing an OpenMP SINGLE directive in the PSyIR.

  • OMPMasterDirective: Class representing an OpenMP MASTER directive in the PSyclone AST.

  • OMPTaskloopDirective: Class representing an OpenMP TASKLOOP directive in the PSyIR.

  • OMPTaskDirective: Class representing an OpenMP TASK directive in the PSyIR after lowering.

  • DynamicOMPTaskDirective: Class representing an OpenMP TASK directive in the PSyIR.

  • OMPDoDirective: Class representing an OpenMP DO directive in the PSyIR.

  • OMPParallelDoDirective: Class for the !$OMP PARALLEL DO directive. This inherits from

  • OMPTaskwaitDirective: Class representing an OpenMP TASKWAIT directive in the PSyIR.

  • OMPTargetDirective: Class for the !$OMP TARGET directive that offloads the code contained

  • OMPLoopDirective: Class for the !$OMP LOOP directive that specifies that the iterations

  • OMPDeclareTargetDirective: Class representing an OpenMP Declare Target directive in the PSyIR.

  • OMPSimdDirective: OpenMP directive to inform that the associated loop can be vectorised.

  • OMPTeamsDistributeParallelDoDirective: Class representing the OMP teams distribute parallel do directive.

  • OMPTeamsLoopDirective: Class representing the OMP teams loop directive.

  • OMPGrainsizeClause: OpenMP grainsize clause, used by OMPTaskloopDirective. Controls the

  • OMPNogroupClause: OpenMP nogroup clause, used by OMPTaskloopDirective to disable the

  • OMPNowaitClause: OpenMP nowait clause. Disable the implicit barrier at the end of the

  • OMPNumTasksClause: OpenMP numtasks clause, used by OMPTaskloopDirective. Controls the number

  • OMPPrivateClause: OpenMP private clause. This is used to declare variables as private

  • OMPDefaultClause: OpenMP Default clause. Used to determine the default declaration for

  • OMPReductionClause: OpenMP Reduction clause.

  • OMPScheduleClause: OpenMP Schedule clause used for OMP Do Directives.

  • OMPFirstprivateClause: OpenMP firstprivate clause. This is used to declare variables as

  • OMPSharedClause: OpenMP shared clause. This is used to declare variables as shared in an

  • OMPDependClause: OpenMP Depend clause used for OpenMP Task directives.

class psyclone.psyir.nodes.ArrayMember(member_name, parent=None)[source]#

Node representing an access to the element(s) of an array that is a member of a structure. Must have one or more children which give the array-index expressions for the array access.

Inheritance

Inheritance diagram of ArrayMember
static create(member_name, indices)[source]#

Construct an ArrayMember instance describing an array access to a member of a structure.

e.g. for the Fortran grid%subdomains(1,2), subdomains must be an array and we are accessing element (1,2) of it. We would therefore create the ArrayMember for this access by calling:

>>> amem = ArrayMember.create("subdomains",
                              [Literal("1", INTEGER_TYPE),
                               Literal("2", INTEGER_TYPE)])
Parameters:
Raises:

GenerationError – if the supplied indices argument is not a list.

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

Node representing a reference to an element or elements of an Array. The array-index expressions are stored as the children of this node.

Inheritance

Inheritance diagram of ArrayReference
static create(symbol, indices)[source]#

Create an ArrayReference instance given a symbol and a list of Node array indices. The special value “:” can be used as an index to create the corresponding PSyIR Range that represents “:”.

Parameters:
Returns:

an ArrayReference instance.

Return type:

psyclone.psyir.nodes.ArrayReference

Raises:

GenerationError – if the arguments to the create method are not of the expected type.

property datatype#
Returns:

the datatype of the accessed array element(s).

Return type:

psyclone.psyir.symbols.DataType

class psyclone.psyir.nodes.ArrayOfStructuresMember(member_name, parent=None)[source]#

Node representing a membership expression of a parent structure where the expression resolves to the component of one or more elements of an array of structures. As such, its first child must be a member of that structure. Subsequent children give the array-index expressions.

Inheritance

Inheritance diagram of ArrayOfStructuresMember
static create(member_name, indices, inner_member)[source]#

Create an access to a member of one or more elements of an array of structures that is itself a member of a structure.

e.g. if we had the Fortran grid%subdomains(1)%xstart then subdomains must be an array of structure (derived) type. We would construct an ArrayOfStructuresMember for this access by calling:

>>> aosmem = ArrayOfStructuresMember.create(
        "subdomains", [Literal("1", INTEGER_TYPE)], Member("xstart"))
Parameters:
  • member_name (str) – the name of the array member of the structure that is being accessed.

  • indices (list of psyclone.psyir.nodes.DataNode) – the array-index expressions.

  • inner_member (psyclone.psyir.nodes.Member) – the member of the member_name structure that is being accessed.

Returns:

a new ArrayOfStructuresMember object.

Return type:

psyclone.psyir.nodes.ArrayOfStructuresMember

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

Node representing an access to a member of one or more elements of an array of structures. Since this access is to a member of the structure, its first child will be a subclass of Member. All subsequent children give the array-index expressions.

Inheritance

Inheritance diagram of ArrayOfStructuresReference
static create(symbol, indices, members, parent=None, overwrite_datatype=None)[source]#

Create a reference to a member of one or more elements of an array of structures.

The symbol to be referred to must be of UnresolvedType, UnsupportedType or ArrayType. If the latter then the ‘intrinsic’ type of the array must be specified with a DataTypeSymbol. The member of the structure that is accessed is specified using the ‘members’ argument. e.g. for a reference to “field(idx)%bundle(2)%flag” this argument would be [(“bundle”, [Literal(“2”, INTEGER4_TYPE)]), “flag”]. The ‘indices’ argument specifies the DataNodes describing the indexing into the array of structures. For the example given previously, this would be [Reference(idx_symbol)] where idx_symbol is the Symbol representing the idx variable in the Fortran code snippet.

Parameters:
  • symbol (psyclone.psyir.symbols.DataSymbol) – the symbol that this reference is to.

  • indices (list of psyclone.psyir.nodes.Node) – a list of Nodes describing the array indices.

  • members (list of str or 2-tuples containing (str, list of nodes describing array access)) – one or more component(s) of the structure(s) that make up the full access. Any components that are array references must provide the name of the array and a list of DataNodes describing which part of it is accessed.

  • parent (sub-class of psyclone.psyir.nodes.Node) – the parent of this node in the PSyIR.

  • overwrite_datatype (Optional[psyclone.psyir.symbols.DataType]) – the datatype for the reference, which will overwrite the value determined by analysing the corresponding user defined type. This is useful when e.g. the module that declares the structure cannot be accessed.

Returns:

an ArrayOfStructuresReference instance.

Return type:

psyclone.psyir.nodes.ArrayOfStructuresReference

Raises:

TypeError – if the arguments to the create method are not of the expected type.

class psyclone.psyir.nodes.Assignment(is_pointer=False, **kwargs)[source]#

Node representing an Assignment statement. As such it has a LHS and RHS as children 0 and 1 respectively.

Parameters:
  • is_pointer (bool) – whether this represents a pointer assignment.

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

Inheritance

Inheritance diagram of Assignment
static create(lhs, rhs, is_pointer=False)[source]#

Create an Assignment instance given lhs and rhs child instances.

Parameters:
  • lhs (psyclone.psyir.nodes.Node) – the PSyIR node containing the left hand side of the assignment.

  • rhs (psyclone.psyir.nodes.Node) – the PSyIR node containing the right hand side of the assignment.

  • is_pointer (bool) – whether this represents a pointer assignment.

Returns:

an Assignment instance.

Return type:

psyclone.psyir.nodes.Assignment

property is_array_assignment#
Returns:

True if the lhs of the assignment is an array access with at least one of its dimensions being a range and False otherwise.

Return type:

bool

property is_literal_assignment#
Returns:

True if the rhs of the assignment is a literal value and False otherwise.

Return type:

bool

property is_pointer#
Returns:

whether this represents a pointer assignment.

Return type:

bool

property lhs#
Returns:

the child node representing the Left-Hand Side of the assignment.

Return type:

psyclone.psyir.nodes.Node

Raises:

InternalError – Node has fewer children than expected.

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).

property rhs#
Returns:

the child node representing the Right-Hand Side of the assignment.

Return type:

psyclone.psyir.nodes.Node

Raises:

InternalError – Node has fewer children than expected.

class psyclone.psyir.nodes.AtomicDirectiveType(*values)[source]#

Enumeration of the available atomic operation types supported by OpenMP and OpenACC.

Inheritance

Inheritance diagram of AtomicDirectiveType
class psyclone.psyir.nodes.AtomicDirectiveMixin[source]#

A mixin class for directives implementing atomic behaviour.

Inheritance

Inheritance diagram of AtomicDirectiveMixin
classmethod is_valid_atomic_statement(stmt)[source]#

Check if a given statement is a valid atomic expression.

Parameters:

stmt (Node) – a node to be validated.

Return type:

bool

Returns:

whether a given statement is compliant with the classes atomic expressions.

class psyclone.psyir.nodes.BinaryOperation(operator, has_explicit_grouping=False, parent=None)[source]#

Node representing a BinaryOperation expression. As such it has two operands as children 0 and 1, and an attribute with the operator type.

Parameters:
  • operator (psyclone.psyir.nodes.BinaryOperation.Operator) – the operator used in the operation.

  • has_explicit_grouping (bool) – Whether this operation should be surrounded by explicit grouping syntax (e.g. parenthesis) regardless of not breaking any other precedence rules. Defaults to False.

  • parent (Optional[psyclone.psyir.nodes.Node]) – the parent node of this Operation in the PSyIR.

Inheritance

Inheritance diagram of BinaryOperation
static create(operator, lhs, rhs, has_explicit_grouping=False)[source]#

Create a BinaryOperator instance given an operator and lhs and rhs child instances with optional names.

Parameters:
  • operator (psyclone.psyir.nodes.BinaryOperation.Operator) – the operator used in the operation.

  • lhs (Union[psyclone.psyir.nodes.Node, Tuple[str, psyclone.psyir.nodes.Node]]) – the PSyIR node containing the left hand side of the assignment, or a tuple containing the name of the argument and the PSyIR node.

  • rhs (Union[psyclone.psyir.nodes.Node, Tuple[str, psyclone.psyir.nodes.Node]]) – the PSyIR node containing the right hand side of the assignment, or a tuple containing the name of the argument and the PSyIR node.

  • has_explicit_grouping (bool) – Whether this operation should be surrounded by explicit grouping syntax (e.g. parenthesis) regardless of not breaking any other precedence rules. Defaults to False.

Returns:

a BinaryOperator instance.

Return type:

psyclone.psyir.nodes.BinaryOperation

Raises:

GenerationError – if the arguments to the create method are not of the expected type.

property datatype#

Determines the datatype of this operation. If it cannot be determined for any reason then an instance of UnresolvedType is returned.

Returns:

the datatype of the result of this BinaryOperation.

Return type:

psyclone.psyir.symbols.DataType

Raises:

InternalError – if the operands are both arrays but are of different shapes.

property has_explicit_grouping: bool#
Returns:

Whether this operation should be surrounded by explicit grouping syntax (e.g. parenthesis) regardless of not breaking any other precedence rules.

property operands: Tuple[DataNode, DataNode]#
Returns:

the operands of this BinaryOperation.

class psyclone.psyir.nodes.Call(**kwargs)[source]#

Node representing a Call. This can be found as a standalone statement or an expression.

TODO #1437: The combined Statement and Expression implementation is simple but it has some shortcomings that may need to be addressed.

Parameters:

kwargs (unwrapped dict.) – additional keyword arguments provided to the PSyIR node.

Inheritance

Inheritance diagram of Call
append_named_arg(name, arg)[source]#

Append a named argument to this call.

Parameters:
Raises:

ValueError – if the name argument is already used for an existing argument.

property argument_names#
Returns:

a list with the name of each argument. If the entry is None then the argument is a positional argument.

Return type:

List[Optional[str]]

property arguments: Tuple[DataNode]#
Returns:

the children of this node that represent its arguments.

Return type:

list[py:class:psyclone.psyir.nodes.DataNode]

copy()[source]#

Return a copy of this node. This is a bespoke implementation for a Call node that ensures that any internal id’s are consistent before and after copying.

Returns:

a copy of this node and its children.

Return type:

psyclone.psyir.node.Call

classmethod create(routine, arguments=())[source]#

Create an instance of class cls given valid instances of a routine symbol, and a list of child nodes (or name and node tuple) for its arguments.

Parameters:
  • routine (py:class:psyclone.psyir.symbols.RoutineSymbol | py:class:psyclone.psyir.nodes.Reference) – the routine that class cls calls.

  • arguments (Optional[Iterable[ Union[psyclone.psyir.nodes.DataNode, Tuple[str, psyclone.psyir.nodes.DataNode]]]]) – optional list of arguments for this call, these can be PSyIR nodes or tuples of string,Node for named arguments.

Returns:

an instance of cls.

Return type:

psyclone.psyir.nodes.Call or a subclass thereof.

Raises:
  • TypeError – if the routine argument is not a RoutineSymbol.

  • GenerationError – if the arguments argument is not an Iterable.

get_argument_map(routine)[source]#

Return a list of indices mapping from each argument of this call to the corresponding entry in the argument list of the supplied routine.

Parameters:

routine (Routine) – the target of this Call.

Return type:

List[int]

Returns:

list of integers referring to matching arguments of the supplied routine.

Raises:

CallMatchingArgumentsNotFound – If there was some problem in finding matching arguments.

get_callee(use_first_callee_and_no_arg_check=False)[source]#

Searches for the implementation(s) of the target routine for this Call including argument checks.

Warning

If use_first_callee_and_no_arg_check is set to True, the very first implementation of a Routine with a matching name will be returned. In this case, the arguments of the Call and the Routine might not match.

Parameters:

use_first_callee_and_no_arg_check (bool) – whether or not (the default) to just find the first potential callee without checking its arguments.

Return type:

Tuple[Routine, List[int]]

Returns:

A tuple of two elements. The first element is the routine that this call targets. The second one a list of arguments providing the information on matching argument indices.

Raises:

NotImplementedError – if the routine is not local and not found in any containers in scope at the call site.

get_callees()[source]#

Searches for the implementation(s) of all potential target routines for this Call. It does not attempt to resolve static polymorphism by checking the argument types.

Return type:

List[Routine]

Returns:

the Routine(s) that this call targets.

Raises:

NotImplementedError – if the routine is not found or a limitation prevents definite determination of the target routine.

insert_named_arg(name, arg, index)[source]#

Insert a named argument to the call.

Parameters:
  • name (Optional[str]) – the argument name.

  • arg (psyclone.psyir.nodes.DataNode) – the argument expression.

  • index (int) – where in the argument list to insert the named argument.

Raises:
  • ValueError – if the name argument is already used for an existing argument.

  • TypeError – if the index argument is the wrong type.

is_available_on_device(device_string='')[source]#
Parameters:

device_string (str) – optional string to identify the offloading device (or its compiler-platform family).

Return type:

bool

Returns:

whether this call is available on an accelerated device.

property is_elemental#
Returns:

whether the routine being called is elemental (provided with an input array it will apply the operation individually to each of the array elements and return an array with the results). If this information is not known then it returns None.

Return type:

NoneType | bool

property is_pure#
Returns:

whether the routine being called is pure (guaranteed to return the same result when provided with the same argument values). If this information is not known then it returns None.

Return type:

NoneType | bool

node_str(colour=True)[source]#

Construct a text representation of this node, optionally containing colour control codes.

Parameters:

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

Returns:

description of this PSyIR node.

Return type:

str

reference_accesses()[source]#

TODO #446 - all arguments that are passed by reference are currently marked as having READWRITE access (unless we know that the routine is PURE). We could do better than this if we have the PSyIR of the called Routine.

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_named_arg(existing_name, arg)[source]#

Replace one named argument node with another node keeping the same name.

Parameters:
  • existing_name (str) – the argument name.

  • arg (DataNode) – the argument expression.

Raises:
  • TypeError – if the name argument is the wrong type.

  • ValueError – if the name argument is already used for an existing argument.

property routine#
Returns:

the routine reference that this call calls.

Return type:

Optional[py:class:psyclone.psyir.nodes.Reference]

class psyclone.psyir.nodes.Clause(ast=None, children=None, parent=None, annotations=None)[source]#

Base abstract class for all clauses.

Inheritance

Inheritance diagram of Clause
property clause_string: str#
Returns:

the base clause string for this Clause.

class psyclone.psyir.nodes.CodeBlock(fp2_nodes, structure, parent=None, annotations=None)[source]#

Node representing some generic Fortran code that PSyclone does not attempt to manipulate. As such it is a leaf in the PSyIR and therefore has no children.

Parameters:
  • fp2_nodes (list[fparser.two.utils.Base]) – the fparser2 parse-tree nodes representing the Fortran code constituting the code block.

  • structure (psyclone.psyir.nodes.CodeBlock.Structure) – argument indicating whether this code block is a statement or an expression.

  • parent (psyclone.psyir.nodes.Node) – the parent node of this code block in the PSyIR.

  • annotations (list[str | NoneType]) – tags that provide additional information about the node. The node should still be functionally correct when ignoring these tags.

Inheritance

Inheritance diagram of CodeBlock
class Structure(*values)[source]#

Enumeration that captures the structure of the code block which may be required when processing.

property get_ast_nodes#
Returns:

the nodes associated with this code block in the original fparser2 parse tree.

Return type:

list[fparser.two.Fortran2003.Base]

get_symbol_names()[source]#

Analyses the fparser2 parse tree associated with this CodeBlock and returns the names of all symbols accessed within it. Since, by definition, we do not understand the contents of a CodeBlock, we do not attempt to analyse how these symbols are accessed - they are all marked as being READWRITE (this includes the names of any routines that might be called).

Note that the names of any Fortran intrinsics are not included in the result. If the original code has unwisely overridden a Fortran intrinsic then fparser may incorrectly identify the use of such a variable/routine as still being an intrinsic call and, as such, it will be omitted from the names returned by this method.

TODO #2863 - these limitations (blanket use of READWRITE and the ignoring of Fortran intrinsics) need to be re-visited.

Return type:

List[str]

Returns:

the symbol names used inside the CodeBock.

has_potential_control_flow_jump()[source]#
Return type:

bool

Returns:

whether this CodeBlock contains a potential control flow jump, e.g. GOTO, EXIT or a labeled statement.

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 control codes for colour.

Returns:

text description of this node.

Return type:

str

reference_accesses()[source]#

Get the symbol access map. Since this is a CodeBlock we only know the names of symbols accessed within it but not how they are accessed. Therefore we err on the side of caution and mark them all as READWRITE, unfortunately, this will include the names of any routines that are called.

TODO #2863 - it would be better to use AccessType.UNKNOWN here but currently VariablesAccessMap does not consider that type of access.

This method makes use of get_symbol_names() and is therefore subject to the same limitations as that method.

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).

property structure#
Returns:

whether this code block is a statement or an expression.

Return type:

psyclone.psyir.nodes.CodeBlock.Structure

valid_annotations = 'psy-data-start'#

The annotations that are supported by this node. psy-data-start - this node has replaced a PSyDataNode during the lowering of the PSyIR to language level.

class psyclone.psyir.nodes.Container(name, **kwargs)[source]#

Node representing a set of Routine and/or Container nodes, as well as a name and a SymbolTable. This construct can be used to scope symbols of variables, Routine names and Container names. In Fortran a container would naturally represent a module or a submodule.

Parameters:

Inheritance

Inheritance diagram of Container
classmethod create(name, symbol_table, children)[source]#

Create a Container instance given a name, a symbol table and a list of child nodes.

Parameters:
Returns:

an instance of cls.

Return type:

psyclone.psyir.nodes.Container or subclass thereof

Raises:

GenerationError – if the arguments to the create method are not of the expected type.

find_routine_psyir(name, allow_private=False)[source]#

Searches the Container for a definition of the named routine with appropriate visibility.

NOTE: if the named routine corresponds to a generic interface then this method will return None. You will need to use resolve_routine first to find the names of the routines that the interface resolves to.

Parameters:
  • name (str) – the name of the Routine for which to search.

  • allow_private (bool) – whether the Routine is permitted to have a visibility of PRIVATE.

Returns:

the PSyIR of the named Routine if found, otherwise None.

Return type:

psyclone.psyir.nodes.Routine | NoneType

property name#
Returns:

name of the container.

Return type:

str

node_str(colour=True)[source]#

Returns the name of this node with appropriate control codes to generate coloured output in a terminal that supports it.

Parameters:

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

Returns:

description of this node, possibly coloured.

Return type:

str

resolve_routine(name)[source]#

This function returns a list of function names that might be actually called when the routine name is called. In most cases this is exactly name, but in case of a generic subroutine the name might change. For now (since we cannot compare routine signatures yet), we return the list of all possible functions that might be called.

If the symbol with the specified name is a generic Symbol and is imported then it is specialised (in place) to become a RoutineSymbol.

Parameters:

name (str) – the name of the routine to resolve

Returns:

the names of those routines that may actually be invoked when the routine name is called or an empty list if there is no routine with that name in this container.

Return type:

list[str | None]

Raises:

TypeError – if the Symbol with the supplied name is not a RoutineSymbol, GenericInterfaceSymbol or imported Symbol.

class psyclone.psyir.nodes.DataNode(ast=None, children=None, parent=None, annotations=None)[source]#

Abstract node representing a general PSyIR expression that represents a value, which has a datatype.

Inheritance

Inheritance diagram of DataNode
property datatype#
Returns:

the data-type of this Node. Currently this base implementation just returns UnresolvedType(). If a sub-class can do better then it must override this method.

Return type:

psyclone.psyir.symbols.UnresolvedType

is_character(unknown_as=None)[source]#
Parameters:

unknown_as (Optional[bool]) – Determines behaviour in the case where it cannot be determined whether the DataNode is a character. Defaults to None, in which case an exception is raised.

Returns:

True if this DataNode is a character, otherwise False.

Return type:

bool

Raises:

ValueError – if the intrinsic type cannot be determined.

class psyclone.psyir.nodes.FileContainer(name, **kwargs)[source]#

PSyIR node to encapsulate the scope of a source file. In the PSyIR, a FileContainer is identical to a Container. However, it is useful to distinguish this type of container for the backends, which can have different constraints/syntax for general Containers and a FileContainer. For example, a FileContainer can not have any symbol table entries in Fortran.

Inheritance

Inheritance diagram of FileContainer
property invokes#

Return the Invokes object associated to this FileContainer. This is for compatibility with old psyclone transformation scripts. Previously, the entry point was PSy, and the script had to find the list of InvokeSchedules, now the entry point is the root FileContainer:

before: PSy -> Invokes -> Invoke -> InvokeSchedule now: FileContainer –^

This method creates a shortcut:
PSy -> Invokes -> Invoke -> InvokeSchedule

^— FileContainer –^

So that previous:
def trans(psy):

psy.invokes.get_invoke(‘name’).schedule

still work as expected. However, it exposes the PSy hierachy to users scripts, so this will eventually be deprecated.

Returns:

the associated Invokes object.

Return type:

psyclone.psyGen.Invokes

Raises:

NoInvokesError – if no InvokeSchedule was found.

class psyclone.psyir.nodes.IfBlock(ast=None, children=None, parent=None, annotations=None)[source]#

Node representing an if-block within the PSyIR. It has two mandatory children: the first one represents the if-condition and the second one the if-body; and an optional third child representing the else-body.

Inheritance

Inheritance diagram of IfBlock
property condition#

Return the PSyIR Node representing the conditional expression of this IfBlock.

Returns:

IfBlock conditional expression.

Return type:

psyclone.psyir.nodes.Node

Raises:

InternalError – If the IfBlock node does not have the correct number of children.

static create(if_condition, if_body, else_body=None)[source]#

Create an IfBlock instance given valid instances of an if_condition, an if_body and an optional else_body.

Parameters:
  • if_condition (psyclone.psyir.nodes.Node) – the PSyIR node containing the if condition of the if block.

  • if_body (List[psyclone.psyir.nodes.Node]) – the PSyIR nodes representing the if body of the if block.

  • else_body (Optional[List[psyclone.psyir.nodes.Node]]) – PSyIR nodes representing the else body of the if block or None if there is no else body (defaults to None).

Returns:

an IfBlock instance.

Return type:

psyclone.psyir.nodes.IfBlock

Raises:

GenerationError – if the arguments to the create method are not of the expected type.

property else_body#

If available return the Schedule executed when the IfBlock evaluates to False, otherwise return None.

Returns:

Schedule to be executed when IfBlock evaluates to False, if it doesn’t exist returns None.

Return type:

psyclone.psyir.nodes.Schedule or NoneType

property if_body#

Return the Schedule executed when the IfBlock evaluates to True.

Returns:

Schedule to be executed when IfBlock evaluates to True.

Return type:

psyclone.psyir.nodes.Schedule

Raises:

InternalError – If the IfBlock node does not have the correct number of children.

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).

class psyclone.psyir.nodes.IntrinsicCall(intrinsic, **kwargs)[source]#

Node representing a call to an intrinsic routine (function or subroutine). This can be found as a standalone statement or an expression.

Parameters:
  • intrinsic (py:class:psyclone.psyir.IntrinsicCall.Intrinsic) – the type of Intrinsic being created.

  • kwargs (unwrapped dict.) – additional keyword arguments provided to the PSyIR node.

Raises:

TypeError – if the ‘intrinsic’ argument is not an Intrinsic type.

Inheritance

Inheritance diagram of IntrinsicCall
class Intrinsic(*values)[source]#

Enum of all intrinsics with their attributes as values using the IAttr namedtuple format:

NAME = IAttr(name, is_pure, is_elemental, is_inquiry,

required_args, optional_args, return_type, reference_accesses)

Note that name is duplicated inside IAttr because each item in the Enum must have a different value, and without the name that would not be guaranteed.

classmethod create(intrinsic, arguments=())[source]#

Create an instance of this class given the type of intrinsic and a list of nodes (or name-and-node tuples) for its arguments. Any named arguments must come after any required arguments.

Parameters:
  • intrinsic (py:class:psyclone.psyir.IntrinsicCall.Intrinsic) – the Intrinsic being called.

  • arguments (Optional[Iterable[ Union[psyclone.psyir.nodes.DataNode, Tuple[str, psyclone.psyir.nodes.DataNode]]]]) – list of arguments for this intrinsic, these can be PSyIR nodes or tuples of string,Node for named arguments.

Returns:

an instance of this class.

Return type:

psyclone.psyir.nodes.IntrinsicCall

Raises:
  • TypeError – if any of the arguments are of the wrong type.

  • ValueError – if any optional arguments have incorrect names or if a positional argument is listed after a named argument.

  • ValueError – if the number of supplied arguments is not valid for the specified intrinsic.

get_all_accessed_symbols()[source]#
Return type:

set[Symbol]

Returns:

a set of all the symbols accessed inside this IntrinsicCall.

property intrinsic#

Return the type of intrinsic.

Returns:

enumerated type capturing the type of intrinsic.

Return type:

psyclone.psyir.nodes.IntrinsicCall.Intrinsic

is_available_on_device(device_string='')[source]#
Parameters:

device_string (str) – optional string to identify the offloading device (or its compiler-platform family).

Return type:

bool

Returns:

whether this intrinsic is available on an accelerated device.

Raises:

ValueError – if the provided ‘device_string’ is not one of the supported values.

property is_elemental#
Returns:

whether the routine being called is elemental (provided with an input array it will apply the operation individually to each of the array elements and return an array with the results). If this information is not known then it returns None.

Return type:

NoneType | bool

property is_inquiry#
Returns:

whether the routine being called is a query function (i.e. returns information about its argument rather than accessing any data referenced by the argument). If this information is not known then it returns None.

Return type:

NoneType | bool

property is_pure#
Returns:

whether the routine being called is pure (guaranteed to return the same result when provided with the same argument values). If this information is not known then it returns None.

Return type:

NoneType | bool

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).

class psyclone.psyir.nodes.Literal(value, datatype, parent=None)[source]#

Node representing a Literal. The value and datatype properties of this node are immutable.

If the node represents “real” data and the value is expressed with an exponent (e.g. 3.2e4 or 0.1E-3) then the stored value always uses a lower case “e”.

Parameters:
Raises:
  • TypeError – if the datatype is not an instance of psyclone.psyir.symbols.DataType.

  • ValueError – if the datatype is not one of self.VALID_DATA_TYPES.

  • TypeError – if the supplied value is not a string.

  • ValueError – if the supplied value is an empty string and the Literal is not a CHARACTER.

  • ValueError – if the Literal is a BOOLEAN and the value is not ‘true’ or ‘false’.

  • ValueError – if the Literal is a REAL but does not conform to the supported format defined by the _real_value property.

  • ValueError – if the Literal is an INTEGER but does not conform to the supported format defined by the _int_value property.

Inheritance

Inheritance diagram of Literal
property datatype#
Returns:

the type of this Literal.

Return type:

psyclone.psyir.symbols.DataType

get_all_accessed_symbols()[source]#
Return type:

set[Symbol]

Returns:

a set of all the symbols accessed inside this Literal.

node_str(colour=True)[source]#

Construct a text representation of this node, optionally containing colour control codes.

Parameters:

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

Returns:

description of this PSyIR node.

Return type:

str

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]#

Replace any Symbols referred to by this object with those in the supplied SymbolTable (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 value#
Returns:

String representing the literal value.

Return type:

str

class psyclone.psyir.nodes.Loop(variable=None, annotations=None, **kwargs)[source]#

Node representing a loop within the PSyIR. It has 4 mandatory children: the first one represents the loop lower bound, the second one represents the loop upper bound, the third one represents the step value and the fourth one is always a PSyIR Schedule node containing the statements inside the loop body.

(Note: Loop only represents the equivalent to Fortran counted do loops. This means the loop is bounded by start/stop/step expressions evaluated before the loop starts. See WhileLoop for while loops, including the Fortran do while and do loop with no condition.)

Parameters:
  • variable (Optional[psyclone.psyir.symbols.DataSymbol]) – optional reference to the loop iterator variable. Defaults to None.

  • annotations (Optional[List[str]]) – One or more labels that provide additional information about the node (primarily relating to the input code that it was created from).

  • kwargs (unwrapped dict.) – additional keyword arguments provided to the PSyIR node.

Raises:

InternalError – if the ‘was_single_stmt’ annotation is supplied without the ‘was_where’ annotation.

Inheritance

Inheritance diagram of Loop
classmethod create(variable, start, stop, step, children)[source]#

Create a Loop instance given valid instances of a variable, start, stop and step nodes, and a list of child nodes for the loop body.

Parameters:
Returns:

a Loop instance.

Return type:

psyclone.psyir.nodes.Loop

Raises:

GenerationError – if the arguments to the create method are not of the expected type.

property dag_name#

Return the name to use in a dag for this node

Returns:

Return the dag name for this loop

Return type:

string

Raises:

InternalError – if this Loop has no ancestor Routine.

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

This is a Reference method, but sometimes it will reach this point because self.reference_accesses returns a Loop as the Node associated with the loop variable. In this case we can always return False as we know that this variable gets the iteration value.

#TODO #3124: Alternatively move the loop variable to a child Reference.

Parameters:
  • scope – the given scope that we evaluate.

  • visited_nodes – 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.

property explicitly_private_symbols#
Returns:

the set of symbols inside the loop which are private to each iteration of the loop if it is executed concurrently.

Return type:

Set[psyclone.psyir.symbols.DataSymbol]

get_all_accessed_symbols()[source]#
Return type:

set[Symbol]

Returns:

a set of all the symbols accessed inside this Loop.

independent_iterations(test_all_variables=False, signatures_to_ignore=None, dep_tools=None)[source]#

This function analyses a loop in the PSyIR to see whether its iterations are independent.

Parameters:
  • test_all_variables (bool) – if True, it will test if all variable accesses are independent, otherwise it will stop after the first variable access is found that isn’t.

  • signatures_to_ignore (Optional[ List[psyclone.core.Signature]]) – list of signatures for which to skip the access checks.

  • dep_tools (Optional[ psyclone.psyir.tools.DependencyTools]) – an optional instance of DependencyTools so that the caller can access any diagnostic messages detailing why the loop iterations are not independent.

Returns:

True if the loop iterations are independent, False otherwise.

Return type:

bool

property loop_body#
Returns:

the PSyIR Schedule with the loop body statements.

Return type:

psyclone.psyir.nodes.Schedule

property loop_type#
Returns:

the type of this loop, if set.

Return type:

Optional[str]

node_str(colour=True)[source]#

Returns the name of this node with (optional) control codes to generate coloured output in a terminal that supports it.

Parameters:

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

Returns:

description of this node, possibly coloured.

Return type:

str

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]#

Replace the Symbol referred to by this object’s variable and explicit_local_symbols properties with those in the supplied SymbolTable (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.

classmethod set_loop_type_inference_rules(rules)[source]#

Specify the rules that define a loop type by inspecting its variable, name. This affects all instances of the Loop class. For example:

rules = {
    "lon": {"variable": "ji"},
    "lat": {"variable": "jj"}
}
Parameters:

rules (dict[str, dict[str, str]]) – new set of rules for inferring loop_types.

property start_expr#
Returns:

the PSyIR Node representing the Loop start expression.

Return type:

psyclone.psyir.nodes.Node

property step_expr#
Returns:

the PSyIR Node representing the Loop step expression.

Return type:

psyclone.psyir.nodes.Node

property stop_expr#
Returns:

the PSyIR Node representing the Loop stop expression.

Return type:

psyclone.psyir.nodes.Node

property variable#
Returns:

the control variable for this loop.

Return type:

psyclone.psyir.symbols.DataSymbol

class psyclone.psyir.nodes.Member(member_name, parent=None)[source]#

Node representing a membership expression of a structure. As such it is a leaf in the PSyIR tree.

Parameters:
Raises:

TypeError – if the supplied parent is of the wrong type.

Inheritance

Inheritance diagram of Member
get_base_and_depth()[source]#
Returns:

the base Reference that contains this member and the depth where this member is found.

Return type:

tuple[ Optional[psyclone.psyir.node.StructureReference], int]

get_signature_and_indices()[source]#
Returns:

the Signature of this member access, and a list of list of the indices used for each component, which is empty in this case since it is not an array access.

Return type:

tuple[psyclone.core.Signature, List[List[int]]]

property name#
Returns:

the name of this member.

Return type:

str

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

class psyclone.psyir.nodes.Node(ast=None, children=None, parent=None, annotations=None)[source]#

Base class for a PSyIR node.

Parameters:
  • ast (sub-class of fparser.two.Fortran2003.Base) – reference into the fparser2 AST corresponding to this node.

  • children (list of psyclone.psyir.nodes.Node) – the PSyIR nodes that are children of this node.

  • parent (psyclone.psyir.nodes.Node) – that parent of this node in the PSyIR tree.

  • annotations (list of str) – Tags that provide additional information about the node. The node should still be functionally correct when ignoring these tags.

Raises:
  • TypeError – if a parent is supplied that is not an instance of Node.

  • InternalError – if an invalid annotation tag is supplied.

Inheritance

Inheritance diagram of Node
property abs_position#

Find a Node’s absolute position in the tree (starting with 0 if it is the root). Needs to be computed dynamically from the starting position (0) as its position may change.

Returns:

absolute position of a Node in the tree.

Return type:

int

Raises:

InternalError – if the absolute position cannot be found.

addchild(child, index=None)[source]#

Adds the supplied node as a child of this node (at position index if supplied). The supplied node must not have an existing parent.

Parameters:
  • child (psyclone.psyir.nodes.Node) – the node to add as a child of this one.

  • index (Optional[int]) – optional position at which to insert new child. Default is to append new child to the list of existing children.

ancestor(ancestor_type, excluding=None, include_self=False, limit=None, shared_with=None)[source]#

Search back up the tree and check whether this node has an ancestor that is an instance of the supplied type (or tuple of types). If it does then we return it otherwise we return None. An individual (or tuple of) (sub-) class(es) to ignore may be provided via the excluding argument. If include_self is True then the current node is included in the search. If limit is provided then the search ceases if/when the supplied node is encountered. If shared_with is provided, then the ancestor search will find an ancestor of both this node and the node provided as shared_with if such an ancestor exists.

Parameters:
  • ancestor_type (type | Tuple[type, ...]) – class(es) to search for.

  • excluding (Optional[type | Tuple[type, ...]]) – (sub-)class(es) to ignore or None.

  • include_self (bool) – whether or not to include this node in the search.

  • limit (Optional[psyclone.psyir.nodes.Node]) – an optional node at which to stop the search.

  • shared_with (Optional[psyclone.psyir.nodes.Node]) – an optional node which must also have the found node as an ancestor.

Returns:

First ancestor Node that is an instance of any of the requested classes or None if not found.

Return type:

Optional[psyclone.psyir.nodes.Node]

Raises:
  • TypeError – if excluding is provided but is not a type or tuple of types.

  • TypeError – if limit is provided but is not an instance of Node.

property annotations#

Return the list of annotations attached to this Node.

Returns:

List of anotations

Return type:

list of str

property args#

Return the list of arguments associated with this Node. The default implementation assumes the Node has no directly associated arguments (i.e. is not a Kern class or subclass). Arguments of any of this nodes descendants are considered to be associated.

property ast#
Returns:

a reference to that part of the fparser2 parse tree that this node represents or None.

Return type:

sub-class of fparser.two.utils.Base

property ast_end#
Returns:

a reference to the last node in the fparser2 parse tree that represents a child of this PSyIR node or None.

Return type:

sub-class of fparser.two.utils.Base

backward_dependence()[source]#

Returns the closest preceding Node that this Node has a direct dependence with or None if there is not one. Only Nodes with the same parent as self are returned. Nodes inherit their descendants’ dependencies. The reason for this is that for correctness a node must maintain its parent if it is moved. For example a halo exchange and a kernel call may have a dependence between them but it is the loop body containing the kernel call that the halo exchange must not move beyond i.e. the loop body inherits the dependencies of the routines within it.

property children#
Returns:

the immediate children of this Node.

Return type:

List[psyclone.psyir.nodes.Node]

coded_kernels()[source]#

Returns a list of all of the user-supplied kernels (as opposed to builtins) that are beneath this node in the PSyIR.

Returns:

all user-supplied kernel calls below this node.

Return type:

List[psyclone.psyGen.CodedKern]

coloured_name(colour=True)[source]#

Returns the display name of this Node, optionally with colour control codes (requires that the termcolor package be installed).

Parameters:

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

Returns:

the name of this node, optionally with colour control codes.

Return type:

str

compute_cached_abs_positions()[source]#

Cache the absolute positions for all nodes in this node’s root’s tree. This involves computing the absolute positions for all of the nodes in the tree, and storing them.

Raises:

InternalError – if the absolute position cannot be found.

copy()[source]#

Return a copy of this node. This is a bespoke implementation for PSyIR nodes that will deepcopy some of its recursive data-structure (e.g. the children tree), while not copying other attributes (e.g. top-level parent reference).

Returns:

a copy of this node and its children.

Return type:

psyclone.psyir.node.Node

dag(file_name='dag', file_format='svg')[source]#

Create a dag of this node and its children, write it to file and return the graph object.

Parameters:
  • file_name (str) – name of the file to create.

  • file_format (str) – format of the file to create. (Must be one recognised by Graphviz.)

Returns:

the graph object or None (if ‘graphviz’ is not found).

Return type:

graphviz.Digraph or NoneType

Raises:

GenerationError – if the specified file format is not recognised by Graphviz.

dag_gen(graph)[source]#

Output my node’s graph (dag) information and call any children. Nodes with children are represented as two vertices, a start and an end. Forward dependencies are represented as green edges, backward dependencies are represented as red edges (but their direction is reversed so the layout looks reasonable) and parent child dependencies are represented as blue edges.

property dag_name#

Return the dag name for this node. This includes the name of the class and the index of its relative position to the parent Routine. If no parent Routine is found, the index used is the absolute position in the tree.

Returns:

the dag name for this node.

Return type:

str

debug_string()[source]#

Generates a Fortran-like output representation but without lowering high-level nodes. This is fast to generate because it doesn’t deepcopy the tree like the Language backends and its output, although not compilable, is readable for error messages.

Returns:

a Fortran-like output representation of the tree.

Return type:

str

property depth#

Returns this Node’s depth in the tree: 1 for the Schedule and increasing for its descendants at each level. :returns: depth of the Node in the tree :rtype: int

detach()[source]#

Detach this node from the tree it belongs to. This is necessary as a precursor to inserting it as the child of another node.

Returns:

this node detached from its parent.

Return type:

psyclone.psyir.node.Node

following(same_routine_scope=True, include_children=True)[source]#

Return all nodes after itself. Ordering is depth first. If the same_routine_scope argument is set to True (default) then only nodes inside the same ancestor routine are returned. If include_children is set to True (default) children of itself are also returned, otherwise it starts at the next sibiling.

Parameters:
  • same_routine_scope (bool) – an optional (default True) argument that restricts the returned nodes to those belonging to the same ancestor routine.

  • include_children (bool) – an optional (default True) argument that enables including own children, instead of starting from the next sibiling.

Returns:

the list of nodes that follow this one.

Return type:

List[psyclone.psyir.nodes.Node]

following_node(same_routine_scope=True)[source]#
Parameters:

same_routine_scope (bool) – an optional (default True) argument that enables returing only nodes from the same ancestor routine.

Returns:

the next node (the next sibiling, or if it doesn’t have one the first next sibiling of its ancestors).

Return type:

Optional[psyclone.psyir.nodes.Node]

forward_dependence()[source]#

Returns the closest following Node that this Node has a direct dependence with or None if there is not one. Only Nodes with the same parent as self are returned. Nodes inherit their descendants’ dependencies. The reason for this is that for correctness a node must maintain its parent if it is moved. For example a halo exchange and a kernel call may have a dependence between them but it is the loop body containing the kernel call that the halo exchange must not move beyond i.e. the loop body inherits the dependencies of the routines within it.

get_all_accessed_symbols()[source]#
Return type:

set[Symbol]

Returns:

a set of all the symbols accessed inside this Node.

get_sibling_lists(my_type, stop_type=None)[source]#

Recurse through the PSyIR tree and return lists of Nodes that are instances of ‘my_type’ and are immediate siblings. Here ‘my_type’ is either a single class or a tuple of classes. In the latter case all nodes are returned that are instances of any classes in the tuple. The recursion into the tree is stopped if an instance of ‘stop_type’ (which is either a single class or a tuple of classes) is found.

Parameters:
  • my_type (type | Tuple[type, ...]) – the class(es) for which the instances are collected.

  • stop_type (Optional[type | Tuple[type, ...]]) – class(es) at which recursion is halted (optional).

Returns:

list of lists, each of which containing nodes that are instances of my_type and are immediate siblings, starting at and including this node.

Return type:

List[List[psyclone.psyir.nodes.Node]]

property has_constructor_parent#
Returns:

whether the constructor has predefined a parent connection but the parent’s children list doesn’t include this node yet.

Return type:

bool

has_descendant(descendant_type)[source]#
Parameters:

descendant_type (Union[type, tuple[type]]) – type(s) to look for.

Return type:

bool

Returns:

whether the node or any of its descendants is of the given type(s).

immediately_follows(node)[source]#
Parameters:

node – the node to compare it to.

Returns:

whether this node immediately follows the given node.

Return type:

bool

immediately_precedes(node)[source]#
Parameters:

node – the node to compare it to.

Returns:

whether this node immediately precedes the given node.

Return type:

bool

is_descendant_of(potential_ancestor)[source]#

Checks if this node is a descendant of the potential_ancestor node.

Parameters:

potential_ancestor – The Node to check whether its an ancestor of self.

Return type:

bool

Returns:

whether potential_ancestor is an ancestor of this node.

is_openmp_parallel()[source]#
Returns:

True if this Node is within an OpenMP parallel region, False otherwise.

Return type:

bool

is_valid_location(new_node, position='before')[source]#

If this Node can be moved to the new_node (where position determines whether it is before of after the new_node) without breaking any data dependencies then return True, otherwise return False.

Parameters:
  • new_node (psyclone.psyir.nodes.Node) – Node to which this node should be moved.

  • position (str) – either ‘before’ or ‘after’.

Raises:
Returns:

whether or not the specified location is valid for this node.

Return type:

bool

kernels()[source]#
Returns:

all kernels that are descendants of this node in the PSyIR.

Return type:

List[psyclone.psyGen.Kern]

loops()[source]#
Returns:

all loops currently in this schedule.

Return type:

List[psyclone.psyir.nodes.Loop]

lower_to_language_level()[source]#

In-place replacement of high-level concepts into generic language PSyIR constructs. This generic implementation only recurses down to its children, but this method must be re-implemented by Nodes that represent high-level concepts.

Returns:

the lowered version of this node.

Return type:

psyclone.psyir.node.Node

node_str(colour=True)[source]#
Parameters:

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

Returns:

a text description of this node. Will typically be overridden by sub-class.

Return type:

str

origin_string()[source]#

Generates a string with the available information about where this node has been created. It currently only works with Fortran Statements or subchildren of them.

Returns:

a string specifing the origin of this node.

Return type:

str

property parent#
Returns:

the parent node.

Return type:

psyclone.psyir.nodes.Node or NoneType

path_from(ancestor)[source]#

Find the path in the psyir tree between ancestor and node and returns a list containing the path.

The result of this method can be used to find the node from its ancestor for example by:

>>> index_list = node.path_from(ancestor)
>>> cursor = ancestor
>>> for index in index_list:
>>>    cursor = cursor.children[index]
>>> assert cursor is node
Parameters:

ancestor (psyclone.psyir.nodes.Node) – an ancestor node of self to find the path from.

Raises:

ValueError – if ancestor is not an ancestor of self.

Returns:

a list of child indices representing the path between ancestor and self.

Return type:

List[int]

pop_all_children()[source]#

Remove all children of this node and return them as a list.

Returns:

all the children of this node as orphan nodes.

Return type:

list of psyclone.psyir.node.Node

property position#

Find a Node’s position relative to its parent Node (starting with 0 if it does not have a parent).

Returns:

relative position of a Node to its parent

Return type:

int

preceding(reverse=False, same_routine_scope=True)[source]#

Return all nodes before itself. Ordering is depth first. If the same_routine_scope argument is set to True (default) then only nodes inside the same ancestor routine are returned. If the reverse argument is set to True then the node ordering is reversed i.e. returning the nodes closest to this node first.

Parameters:
  • reverse (bool) – an optional (default False) argument that reverses the order of any returned nodes (i.e. makes them ‘closest first’).

  • same_routine_scope (bool) – an optional (default True) argument that restricts the returned nodes to those belonging to the same ancestor routine.

Returns:

the nodes preceding this one in the PSyIR tree.

Return type:

List[psyclone.psyir.nodes.Node]

reductions(reprod=None)[source]#

Return all kernels that have reductions and are descendants of this node. If reprod is not provided, all reductions are returned. If reprod is False, all builtin reductions that are not set to reproducible are returned. If reprod is True, all builtins that are set to reproducible are returned.

Parameters:

reprod (Optional[bool]) – if provided, filter reductions by whether or not they are set to be reproducible.

Returns:

all kernels involving reductions that are descendants of this node.

Return type:

List[psyclone.psyir.nodes.Kern]

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]#

Replace any Symbols referred to by this object with those in the supplied SymbolTable (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.

This base implementation simply propagates the call to any child Nodes.

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.

replace_with(node, keep_name_in_context=True)[source]#

Removes self, and its descendants, from the PSyIR tree to which it is connected, and replaces it with the supplied node (and its descendants).

Parameters:
  • node (psyclone.psyir.nodes.node) – the node that will replace self in the PSyIR tree.

  • keep_name_in_context (bool) – whether to conserve the name referencing this node.

Raises:
  • TypeError – if the argument ‘node’ is not a Node.

  • TypeError – if the argument ‘keep_name_in_context’ is not bool.

  • GenerationError – if this node does not have a parent.

  • GenerationError – if the argument ‘node’ has a parent.

property root#
Returns:

the root node of the PSyIR tree.

Return type:

psyclone.psyir.nodes.Node

sameParent(node_2)[source]#
Returns:

True if node_2 has the same parent as this node, False otherwise.

Return type:

bool

property scope#

Some nodes (e.g. Schedule and Container) allow symbols to be scoped via an attached symbol table. This property returns the closest ScopingNode node including self.

Returns:

the closest ancestor ScopingNode node.

Return type:

psyclone.psyir.node.ScopingNode

Raises:

SymbolError – if there is no ScopingNode ancestor.

property siblings#
Returns:

list of sibling nodes, including self.

Return type:

List[psyclone.psyir.nodes.Node]

update_parent_symbol_table(new_parent)[source]#

Specify how this node must update its parent’s symbol table (if it has one) when its parent is updated.

This base implementation does nothing.

Parameters:

new_parent (psyclone.psyir.nodes.ScopingNode) – The new parent of this node.

update_signal()[source]#

Called whenever there is a change in the PSyIR tree below this node. It is responsible for ensuring that this method does not get called recursively and then calls the _update_node() method of the current node (which is the only part that subclasses should specialise). Finally, it propagates the update signal up to the parent node (if any).

validate_global_constraints()[source]#

Validates this Node in the context of the whole PSyIR tree. Although there are validation checks for the parent<->child relationships, there are other constraints that can only be checked once the tree is complete and all transformations have been applied. (One example is that an OMP Do directive must be within the scope of an OMP Parallel directive.)

By default, this routine does nothing. It must be overridden appropriately in any sub-classes to which constraints apply. If an error is found then a GenerationError should be raised.

view(depth=0, colour=True, indent='    ', _index=None)[source]#

Output a human readable description of the current node and all of its descendants as a string.

Parameters:
  • depth (int) – depth of the tree hierarchy for output text. Defaults to 0.

  • colour (bool) – whether to include colour coding in the output. Defaults to True.

  • indent (str) – the indent to apply as the depth increases. Defaults to 4 spaces.

  • _index (int) – the position of this node wrt its siblings or None. Defaults to None.

Returns:

a representation of this node and its descendants.

Return type:

str

Raises:
  • TypeError – if one of the arguments is the wrong type.

  • ValueError – if the depth argument is negative.

walk(my_type, stop_type=None, depth=None)[source]#

Recurse through the PSyIR tree and return all objects that are an instance of ‘my_type’, which is either a single class or a tuple of classes. In the latter case all nodes are returned that are instances of any classes in the tuple. The recursion into the tree is stopped if an instance of ‘stop_type’ (which is either a single class or a tuple of classes) is found. This can be used to avoid analysing e.g. inlined kernels, or as performance optimisation to reduce the number of recursive calls. The recursion into the tree is also stopped if the (optional) ‘depth’ level is reached.

Parameters:
  • my_type (type | Tuple[type, ...]) – the class(es) for which the instances are collected.

  • stop_type (Optional[type | Tuple[type, ...]]) – class(es) at which recursion is halted (optional).

  • depth (Optional[int]) – the depth value the instances must have (optional).

Returns:

list with all nodes that are instances of my_type starting at and including this node.

Return type:

List[psyclone.psyir.nodes.Node]

class psyclone.psyir.nodes.OperatorClause(ast=None, children=None, parent=None, annotations=None)[source]#

Base abstract class for all clauses that have an operator.

Inheritance

Inheritance diagram of OperatorClause
property operator: Any#

Returns the operand for this Clause.

class psyclone.psyir.nodes.Operation(operator, parent=None)[source]#

Abstract base class for PSyIR nodes representing operators.

Parameters:
  • operator (Union[ psyclone.psyir.nodes.UnaryOperation.Operator, psyclone.psyir.nodes.BinaryOperation.Operator]) – the operator used in the operation.

  • parent (Optional[psyclone.psyir.nodes.Node]) – the parent node of this Operation in the PSyIR.

Raises:

TypeError – if the supplied operator is not an instance of self.Operator.

Inheritance

Inheritance diagram of Operation
Operator#

alias of object

node_str(colour=True)[source]#

Construct a text representation of this node, optionally with control codes for coloured display in a suitable terminal.

Parameters:

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

Returns:

description of this PSyIR node.

Return type:

str

property operator#

Return the operator.

Returns:

Enumerated type capturing the operator.

Return type:

Union[ psyclone.psyir.nodes.UnaryOperation.Operator psyclone.psyir.nodes.BinaryOperation.Operator]

class psyclone.psyir.nodes.Range(ast=None, children=None, parent=None, annotations=None)[source]#

The Range node is used to capture a range of integers via start, stop and step expressions. For example, start=2, stop=6 and step=2 indicates the values 2, 4 and 6.

At the moment the only valid use of Range in the PSyIR is to describe a set of accesses to an Array dimension (so-called array notation in Fortran). Therefore, the parent of a Range node should only be an Array node.

The Range node has three children nodes, the first child captures the start of the range, the second child captures the end of the range and the third captures the step within the range.

The nodes for each of the children must return an integer. Potentially valid nodes are therefore Literal, Reference, Operation and CodeBlock.

A common use case is to want to specify all the elements of a given array dimension without knowing the extent of that dimension. In the PSyIR this is achieved by using the LBOUND, and UBOUND intrinsics:

>>> one = Literal("1", INTEGER_TYPE)
>>> # Declare a 1D real array called 'a' with 10 elements
>>> symbol = DataSymbol("a", ArrayType(REAL_TYPE, [10]))
>>> # Return the lower bound of the first dimension of array 'a'
>>> lbound = IntrinsicCall.create(
        IntrinsicCall.Intrinsic.LBOUND,
        [Reference(symbol), one.copy()])
>>> # Return the upper bound of the first dimension of array 'a'
>>> ubound = IntrinsicCall.create(
        IntrinsicCall.Intrinsic.UBOUND,
        [Reference(symbol), one.copy()])
>>> # Step defaults to 1 so no need to include it when creating range
>>> my_range = Range.create(lbound, ubound)
>>> # Create an access to all elements in the 1st dimension of array 'a'
>>> array_access = ArrayReference.create(symbol, [my_range])

In Fortran the above access array_access can be represented by a(:). The Fortran front-ends and back-ends are aware of array notation. Therefore the Fortran frontend is able to convert array notation to PSyIR and the Fortran backend is able to convert PSyIR back to array notation.

Inheritance

Inheritance diagram of Range
static create(start, stop, step=None)[source]#

Create an internally-consistent Range object. If no step is provided then it defaults to an integer Literal with value 1.

Parameters:
Returns:

a fully-populated Range object.

Return type:

psyclone.psyir.nodes.ranges.Range

property start#

Checks that this Range is valid and then returns the PSyIR for the starting value of the range.

Returns:

the starting value of this range.

Return type:

psyclone.psyir.nodes.Node

property step#

Checks that this Range is valid and then returns the step (increment) value/expression.

Returns:

the increment used in this range.

Return type:

psyclone.psyir.nodes.Node

property stop#

Checks that this Range is valid and then returns the end value/expression.

Returns:

the end value of this range.

Return type:

psyclone.psyir.nodes.Node

class psyclone.psyir.nodes.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

class psyclone.psyir.nodes.Return(ast=None, children=None, parent=None, annotations=None)[source]#

Node representing a Return statement (subroutine break without return value).

Inheritance

Inheritance diagram of Return
class psyclone.psyir.nodes.Routine(symbol, is_program=False, **kwargs)[source]#

A sub-class of a Schedule that represents a subroutine, function or program unit.

Parameters:
  • symbol (psyclone.psyir.symbols.RoutineSymbol) – the Symbol used to represent this Routine in its Container.

  • is_program (Optional[bool]) – whether this Routine represents the entry point into a program (e.g. Fortran Program or C main()). Default is False.

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

Raises:

TypeError – if any of the supplied arguments are of the wrong type.

Inheritance

Inheritance diagram of Routine
check_outer_scope_accesses(call, kern_or_call, permit_unresolved=True, ignore_non_data_accesses=False)[source]#

Check for unresolved symbols or for any declared in the outer scope Container of the target routine.

Parameters:
  • call (Union[CodedKern, Call]) – the node representing the call to the routine that is to be inlined.

  • kern_or_call (str) – text appropriate to whether we have a PSyKAl Kernel or a generic routine.

  • permit_unresolved (bool) – whether or not the presence of unresolved symbols will result in an error being raised.

  • ignore_non_data_accesses (bool) – ignore unresolved symbols if they do not represent data accesses (e.g. provide type information).

Raises:
  • SymbolError – if there is an access to an unresolved symbol and permit_unresolved is False.

  • SymbolError – if there is an access to a symbol that is declared in the parent scope of this routine.

classmethod create(name, symbol_table=None, children=None, is_program=False, return_symbol_name=None)[source]#

Create an instance of the supplied class given a name, a symbol table and a list of child nodes. This is implemented as a classmethod so that it is able to act as a Factory for subclasses - e.g. it will create a KernelSchedule if called from KernelSchedule.create().

Parameters:
  • name (str) – the name of the Routine (or subclass).

  • symbol_table (Optional[psyclone.psyGen.SymbolTable]) – the symbol table associated with this Routine.

  • children (Optional[list of psyclone.psyir.nodes.Node]) – a list of PSyIR nodes contained in the Routine.

  • is_program (Optional[bool]) – whether this Routine represents the entry point into a program (e.g. Fortran Program or C main()). Default is False.

  • return_symbol_name (str) – name of the symbol that holds the return value of this routine (if any). Must be present in the supplied symbol table.

Returns:

an instance of cls.

Return type:

psyclone.psyir.nodes.Routine or subclass

Raises:

TypeError – if the arguments to the create method are not of the expected type.

property dag_name#
Returns:

the name of this node in the dag.

Return type:

str

property is_program#
Returns:

whether this Routine represents the entry point into a program (e.g. is a Fortran Program or a C main()).

Return type:

bool

property name#
Returns:

the name of this Routine.

Return type:

str

node_str(colour=True)[source]#

Returns the name of this node with (optional) control codes to generate coloured output in a terminal that supports it.

Parameters:

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

Returns:

description of this node, possibly coloured.

Return type:

str

replace_with(node, keep_name_in_context=True)[source]#

Removes self and its descendants from the PSyIR tree to which it is connected and replaces it with the supplied node (and its descendants).

The node must be a Routine (or subclass) and has the same Symbol as self.

keep_name_in_context is ignored for this replace_with implementation, however we keep the argument to match with the base implementation.

Parameters:
Raises:
  • TypeError – if the argument node is not a Routine.

  • GenerationError – if this node does not have a parent.

  • GenerationError – if the argument ‘node’ has a parent

  • GenerationError – if self and node do not have the same Symbol.

property return_symbol#
Returns:

the symbol which will hold the return value of this Routine or None if the Routine is not a function.

Return type:

psyclone.psyir.symbols.DataSymbol or NoneType

property symbol#
Returns:

the RoutineSymbol corresponding to this Routine.

Return type:

psyclone.psyir.symbols.RoutineSymbol or NoneType

update_parent_symbol_table(new_parent)[source]#

Update the Routine’s new parent’s symbol tables with the corresponding RoutineSymbol.

Parameters:

new_parent (psyclone.psyir.nodes.ScopingNode) – The new parent of this node.

Raises:
  • GenerationError – if a symbol with the same name already exists in the scope.

  • GenerationError – if a Routine with the same name already exists in the scope.

  • GenerationError – if a Codeblock representing a routine with the same name already exists in the scope.

class psyclone.psyir.nodes.Schedule(children=None, parent=None, symbol_table=None)[source]#

Stores schedule information for a sequence of statements (supplied as a list of children).

Inheritance

Inheritance diagram of Schedule
class psyclone.psyir.nodes.Statement(ast=None, children=None, parent=None, annotations=None)[source]#

Abstract node representing a general PSyIR Statement.

Inheritance

Inheritance diagram of Statement
class psyclone.psyir.nodes.StructureMember(member_name, parent=None)[source]#

Node representing a membership expression of the parent’s Reference that resolves into another structure.

Inheritance

Inheritance diagram of StructureMember
static create(member_name, inner_member)[source]#

Given the name of a structure member of a structure and a Member node describing the access to a component of it, construct a StructureMember.

e.g. if we had the following Fortran access: grid%subdomain%xstart then ‘subdomain’ must itself be of structure type and we are accessing the ‘xstart’ component of it. We would therefore create the StructureMember for this by calling:

>>> smem = StructureMember.create("subdomain", Member("xstart"))
Parameters:
  • member_name (str) – name of the structure member.

  • inner_member (sub-class of psyclone.psyir.nodes.Member) – a Member describing the access to a component of the named structure member.

get_signature_and_indices()[source]#
Returns:

the Signature of this structure member, and a list of the indices used for each component (empty list for this component, since the access is not an array - but other components might have indices).

Return type:

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

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

Node representing a reference to a component of a structure. As such it must have a single child representing the component being accessed.

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 StructureReference
static create(symbol, members, parent=None, overwrite_datatype=None)[source]#

Create a StructureReference instance given a symbol and a list of components. e.g. for “field%bundle(2)%flag” this list would be [(“bundle”, [Literal(“2”, INTEGER4_TYPE)]), “flag”].

Parameters:
  • symbol (psyclone.psyir.symbols.DataSymbol) – the symbol that this reference is to.

  • members (list of str or 2-tuples containing (str, list of nodes describing array access)) – the component(s) of the structure that make up the full access. Any components that are array accesses must provide the name of the array and a list of DataNodes describing which part of it is accessed.

  • parent (sub-class of psyclone.psyir.nodes.Node) – the parent of this node in the PSyIR.

  • overwrite_datatype (Optional[psyclone.psyir.symbols.DataType]) – the datatype for the reference, which will overwrite the value determined by analysing the corresponding user defined type. This is useful when e.g. the module that declares the structure cannot be accessed.

Returns:

a StructureReference instance.

Return type:

psyclone.psyir.nodes.StructureReference

Raises:

TypeError – if the supplied symbol is not a DataSymbol.

property datatype#

Walks down the list of members making up this reference to determine the type that it refers to. If an overwrite datatype was given to this reference, this datatype will be returned instead of determining the type.

In order to minimise code duplication, this method also supports ArrayOfStructuresReference by simply allowing for the case where the starting reference is to an Array.

Returns:

the datatype of this reference.

Return type:

psyclone.psyir.symbols.DataType

Raises:

NotImplementedError – if the structure reference represents an array of arrays.

get_signature_and_indices()[source]#
Returns:

the Signature of this structure reference, and a list of the indices used for each component (empty list if an access is not an array).

Return type:

Tuple[psyclone.core.Signature, List[List[psyclone.psyir.nodes.Node]]]

class psyclone.psyir.nodes.UnaryOperation(operator, parent=None)[source]#

Node representing a UnaryOperation expression. As such it has one operand as child 0, and an attribute with the operator type.

Inheritance

Inheritance diagram of UnaryOperation
static create(operator, operand)[source]#

Create a UnaryOperation instance given an operator and operand.

Parameters:
  • operator (psyclone.psyir.nodes.UnaryOperation.Operator) – the specified operator.

  • operand (Union[psyclone.psyir.nodes.Node, Tuple[str, psyclone.psyir.nodes.Node]]) – the PSyIR node that oper operates on, or a tuple containing the name of the argument and the PSyIR node.

Returns:

a UnaryOperation instance.

Return type:

psyclone.psyir.nodes.UnaryOperation

Raises:

GenerationError – if the arguments to the create method are not of the expected type.

property datatype#
Returns:

the datatype of the result of this UnaryOperation.

Return type:

psyclone.psyir.symbols.DataType

property operand: DataNode#
Returns:

the operand of this UnaryOperation.

class psyclone.psyir.nodes.ScopingNode(children=None, parent=None, symbol_table=None)[source]#

Abstract node that has an associated Symbol Table to keep track of symbols declared in its scope (symbols that can be accessed by this node and any of its descendants). If a pre-existing symbol table is provided, it will be attached to the node (raising an error if the symbol table is already attached to another scope), otherwise a new empty Symbol Table will be created.

Parameters:

Inheritance

Inheritance diagram of ScopingNode
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 (and its descendants) 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.

Since this is a ScopingNode, it is associated with a symbol table. Therefore, if the supplied table is the one for the scope containing this node (if any), the one passed to the child nodes is updated to be the one associated with this node.

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_table#
Returns:

table containing symbol information for this scope.

Return type:

psyclone.psyGen.SymbolTable

class psyclone.psyir.nodes.WhileLoop(ast=None, children=None, parent=None, annotations=None)[source]#

Node representing a while loop within the PSyIR. It has two mandatory children: the first one represents the loop condition and the second one the loop body.

Inheritance

Inheritance diagram of WhileLoop
property condition#

Return the PSyIR Node representing the conditional expression of this WhileLoop.

Returns:

WhileLoop conditional expression.

Return type:

psyclone.psyir.nodes.Node

Raises:

InternalError – If the WhileLoop node does not have the correct number of children.

static create(loop_condition, loop_body)[source]#

Create a WhileLoop instance given valid instances of a loop_condition and a loop_body.

Parameters:
Returns:

a WhileLoop instance.

Return type:

psyclone.psyir.nodes.WhileLoop

Raises:

GenerationError – if the arguments to the create method are not of the expected type.

property loop_body#

Return the Schedule executed when the WhileLoop condition is True.

Returns:

Schedule to be executed when WhileLoop condition is True.

Return type:

psyclone.psyir.nodes.Schedule

Raises:

InternalError – If the WhileLoop node does not have the correct number of children.

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).

class psyclone.psyir.nodes.KernelSchedule(symbol, is_program=False, **kwargs)[source]#

A KernelSchedule is the parent node of the PSyIR for Kernel source code.

Inheritance

Inheritance diagram of KernelSchedule
class psyclone.psyir.nodes.PSyDataNode(ast=None, children=None, parent=None, options=None)[source]#

This class can be inserted into a schedule to instrument a set of nodes. Instrument means that calls to an external library using the PSyData API will be inserted before and after the child nodes, which will give that library access to fields and the fact that a region is executed. This can be used, for example, to add performance profiling calls, in-situ visualisation of data, or for writing fields to a file (e.g. for creating test cases, or using driver to run a certain kernel only). The node allows specification of a class string which is used as a prefix for the PSyData module name (prefix_psy_data_mod) and for the PSyDataType (prefix_PSyDataType).

Parameters:
  • ast (sub-class of fparser.two.Fortran2003.Base) – reference into the fparser2 parse tree corresponding to this node.

  • children (list[psyclone.psyir.nodes.Node]) – the PSyIR nodes that are children of this node. These will be made children of the child Schedule of this PSyDataNode.

  • parent (psyclone.psyir.nodes.Node) – the parent of this node in the PSyIR tree.

  • options (Optional[dict[str, Any]]) – a dictionary with options for transformations.

  • options["prefix"] (str) – a prefix to use for the PSyData module name (prefix_psy_data_mod) and the PSyDataType (prefix_PSyDataType) - a “_” will be added automatically. It defaults to “”, which means the module name used will just be psy_data_mod, and the data type PSyDataType.

  • options["region_name"] (tuple[str,str]) – an optional name to use for this PSyDataNode, provided as a 2-tuple containing a module name followed by a local name. The pair of strings should uniquely identify a region unless aggregate information is required (and is supported by the runtime library).

Raises:

InternalError – if a prefix is specified that is not listed in the configuration file.

Inheritance

Inheritance diagram of PSyDataNode
add_psydata_class_prefix(symbol)[source]#

Returns a string prefixed with the class-specific prefix, e.g. if the prefix string is “profile”, then the symbol “PSyDataType” will become “profilePSyDataType”. Typically the _prefix will contain a trailing “_”.

Parameters:

symbol (str) – the symbol name to add the prefix to.

Returns:

the symbol name with the class string as prefix.

Return type:

str

classmethod create(children, symbol_table, ast=None, options=None)[source]#

Creates a new (sub-class of a) PSyData node with the supplied ‘children’ nodes as its children. The symbols used by the PSyData API are added to the supplied symbol table. This is a class method so that it acts as a factory for the various sub-classes of PSyDataNode.

Parameters:
  • children (list[psyclone.psyir.nodes.Node]) – the PSyIR nodes that will become children of the new PSyData node.

  • symbol_table (psyclone.psyir.symbols.SymbolTable) – the associated SymbolTable to which symbols must be added.

  • options (Optional[dict[str, Any]]) – a dictionary with options for transformations.

  • options[prefix"] (str) – a prefix to use for the PSyData module name (prefix_psy_data_mod) and the PSyDataType (prefix_PSyDataType) - a “_” will be added automatically. It defaults to “”, which means the module name used will just be psy_data_mod, and the data type PSyDataType.

  • options["region_name"] (tuple[str,str]) – an optional name to use for this PSyDataNode, provided as a 2-tuple containing a module name followed by a local name. The pair of strings should uniquely identify a region unless aggregate information is required (and is supported by the runtime library).

Parent ast:

reference to fparser2 parse tree for the routine being instrumented with PSyData calls.

Raises:

TypeError – if the supplied children or symbol table are not of the correct type.

property fortran_module#
Returns:

name of the PSyData interface Fortran module.

Return type:

str

generate_symbols(symbol_table)[source]#

Generate the necessary symbols to import and use this PSyDataNode in the provided symbol_table if they don’t already exist.

Parameters:

symbol_table (psyclone.psyir.symbols.SymbolTable) – the associated SymbolTable to which symbols must be added.

lower_to_language_level(options=None)[source]#

Lowers this node (and all children) to language-level PSyIR. The PSyIR tree is modified in-place. This PSyDataNode is replaced by a pair of Fortran-specific CodeBlocks (representing the calls to the start and stop procedures) with the body (children) of the PSyDataNode inserted between them. This use of CodeBlocks means that currently only the Fortran backend is capable of producing code representing the PSyDataNode.

Parameters:
  • options (Optional[dict[str, Any]]) – dictionary of the PSyData generation options.

  • options["pre_var_list"] (list[tuple[str, str]]) – container- and variable-names to be supplied before the first child. The container names are supported to be able to handle variables that are imported from a different container (module in Fortran).

  • options["post_var_list"] (list[tuple[str, str]]) – container- and variable-names to be supplied after the last child. The container names are supported to be able to handle variables that are imported from a different container (module in Fortran).

  • options["pre_var_postfix"] (str) – an optional postfix that will be added to each variable name in the pre_var_list.

  • options["post_var_postfix"] (str) – an optional postfix that will be added to each variable name in the post_var_list.

Returns:

the lowered version of this node.

Return type:

psyclone.psyir.node.Node

Raises:

GenerationError – if the node is not inside a Routine.

property module_name#

Returns the _module_name of this PSyDataNode.

Returns:

the _module_name of this PSyDataNode.

Return type:

str

property options#
Returns:

the option dictionary of this class.

Return type:

dict[str,Any]

property prefix#

Returns the _prefix member of this PSyDataNode.

Returns:

the _prefix member of this PSyDataNode.

Return type:

str

property psy_data_body#
Returns:

the Schedule associated with this PSyData region.

Return type:

psyclone.psyir.nodes.Schedule

Raises:

InternalError – if this PSyData node does not have a Schedule as its one and only child.

property region_identifier#
Returns:

the unique region identifier, which is a tuple consisting of the module name and region name.

Return type:

tuple[str, str]

property region_name#

Returns the _region_name of this PSyDataNode.

Returns:

the _region_name of this PSyDataNode.

Return type:

str

set_region_identifier(module_name, region_name)[source]#

Defines a unique region identifier based on module- and region-name. Typically the names will be concatenated to create a file name or a region name. Since the region name is unique in the module, concatenating the strings will then result in a unique region name.

Parameters:
  • module_name (str) – name of the module.

  • region_name (str) – name of the region.

property type_name#
Returns:

the name of the Fortran derived type associated with this PSyData object.

Return type:

str

property var_name#

Returns the _var_name member of this PSyDataNode.

Returns:

the _var_name of this PSyDataNode.

Return type:

str

class psyclone.psyir.nodes.ExtractNode(ast=None, children=None, parent=None, options=None)[source]#

This class can be inserted into a Schedule to mark Nodes for code extraction using the ExtractRegionTrans transformation. By applying the transformation the Nodes marked for extraction become children of (the Schedule of) an ExtractNode.

Parameters:
  • ast (sub-class of fparser.two.Fortran2003.Base) – reference into the fparser2 parse tree corresponding to this node.

  • children (list of psyclone.psyir.nodes.Node) – the PSyIR nodes that are children of this node.

  • parent (psyclone.psyir.nodes.Node) – the parent of this node in the PSyIR tree.

  • options (Optional[Dict[str, Any]]) – a dictionary with options provided via transformations.

  • options["prefix"] (str) – a prefix to use for the PSyData module name (prefix_psy_data_mod) and the PSyDataType (prefix_PSyDataType) - a “_” will be added automatically. It defaults to “extract”, which means the module name used will be extract_psy_data_mode, and the data type extract_PSyDataType.

  • options["post_var_postfix"] (str) – a postfix to be used when creating names to store values of output variable. A variable ‘a’ would store its value as ‘a’, and its output values as ‘a_post’ with the default post_var_postfix of ‘_post’.

  • options["read_write_info"] (py:class:psyclone.psyir.tools.ReadWriteInfo) – information about variables that are read and/or written in the instrumented code.

Inheritance

Inheritance diagram of ExtractNode
static bring_external_symbols(read_write_info, symbol_table)[source]#

Use the ModuleManager to explore external dependencies and bring symbols used in other modules into scope (with ImportInterface). The symbols will be tagged with a ‘signature@module_name’ tag.

Parameters:
static determine_postfix(read_write_info, postfix='_post')[source]#

This function prevents any name clashes that can occur when adding the postfix to output variable names. For example, if there is an output variable ‘a’, the driver (and the output file) will contain two variables: ‘a’ and ‘a_post’. But if there is also another variable called ‘a_post’, a name clash would occur (two identical keys in the output file, and two identical local variables in the driver). In order to avoid this, the suffix ‘post’ is changed (to ‘post0’, ‘post1’, …) until any name clashes are avoided. This works for structured and non-structured types.

Parameters:
  • read_write_info (psyclone.psyir.tools.ReadWriteInfo) – information about all input and output parameters.

  • postfix (str) – the postfix to append to each output variable.

Return type:

str

Returns:

a postfix that can be added to each output variable without generating a name clash.

property extract_body#
Returns:

the Schedule associated with this ExtractNode.

Return type:

psyclone.psyir.nodes.Schedule

flatten_references()[source]#

Replace StructureReferencces with a simple Reference and a flattened name (replacing all % with _).

get_unique_region_name(nodes)[source]#

This function returns the region and module name. If they are specified in the user options, these names will just be returned (it is then up to the user to guarantee uniqueness). Otherwise a name based on the module and invoke will be created using indices to make sure the name is unique.

Parameters:

nodes (List[Node]) – a list of nodes.

lower_to_language_level()[source]#

Lowers this node (and all children) to language-level PSyIR. The PSyIR tree is modified in-place.

Returns:

the lowered version of this node.

Return type:

psyclone.psyir.node.Node

property post_name#
Returns:

the _post_name member of this ExtractNode.

Return type:

str

class psyclone.psyir.nodes.ProfileNode(ast=None, children=None, parent=None, options=None)[source]#

This class can be inserted into a schedule to create profiling code.

Inheritance

Inheritance diagram of ProfileNode
class psyclone.psyir.nodes.ReadOnlyVerifyNode(ast=None, children=None, parent=None, options=None)[source]#

This class can be inserted into a Schedule to mark Nodes for read-only-verification. By applying the ReadOnlyVerifyTrans transformation, the Nodes marked for extraction become children of (the Schedule of) a ReadOnlyVerifyNode.

Inheritance

Inheritance diagram of ReadOnlyVerifyNode
lower_to_language_level()[source]#

Lowers this node (and all children) to language-level PSyIR. The PSyIR tree is modified in-place.

Returns:

the lowered version of this node.

Return type:

psyclone.psyir.node.Node

property read_only_verify_body#
Returns:

the Schedule associated with this ExtractNode.

Return type:

psyclone.psyir.nodes.Schedule

class psyclone.psyir.nodes.ValueRangeCheckNode(ast=None, children=None, parent=None, options=None)[source]#

This class can be inserted into a Schedule to mark Nodes for NAN-checking using the NanTestTrans transformation. The Nodes marked for checking become children of (the Schedule of) a ValueRangeCheckNode.

Inheritance

Inheritance diagram of ValueRangeCheckNode
lower_to_language_level()[source]#

Lowers this node (and all children) to language-level PSyIR. The PSyIR tree is modified in-place.

Returns:

the lowered version of this node.

Return type:

psyclone.psyir.node.Node

property value_range_check_body#
Returns:

the Schedule associated with this ValueRangeCheckNode.

Return type:

psyclone.psyir.nodes.Schedule

class psyclone.psyir.nodes.Directive(ast=None, children=None, parent=None, annotations=None)[source]#

Abstract base class for all Directive statements.

Inheritance

Inheritance diagram of Directive
abstract property clauses#
Returns:

the Clauses associated with this directive.

Return type:

List of psyclone.psyir.nodes.Clause

create_data_movement_deep_copy_refs()[source]#

Creates the References required to perform a deep copy (in e.g. OpenACC or OpenMP) of all of the quantities accessed in Nodes below this one in the tree. It distringuishes between those quantities that are only read, only written or are both read and written. The necessary References are added to the returned OrderedDicts in the order in which they must be copied.

Returns:

a 3-tuple containing dicts describing the quantities that are read-only, write-only and readwrite. Each dict contains References indexed by Signatures.

Return type:

Tuple[OrderedDict[psyclone.core.Signature, psyclone.psyir.nodes.Reference]]

class psyclone.psyir.nodes.RegionDirective(ast=None, children=None, parent=None)[source]#

Base class for all Directive nodes that have an associated region of code with them.

All classes that generate RegionDirective statements (e.g. OpenMP, OpenACC, compiler-specific) inherit from this class.

Parameters:
  • ast (Optional[fparser.two.Fortran2003.Base]) – the entry in the fparser2 parse tree representing the code contained within this directive or None.

  • children (Optional[List[psyclone.psyir.nodes.Node]]) – the nodes that will be children of this Directive node or None.

  • parent (Optional[psyclone.psyir.nodes.Node]) – PSyIR node that is the parent of this Directive or None.

Inheritance

Inheritance diagram of RegionDirective
property clauses: Tuple[Clause]#
Returns:

the Clauses associated with this directive.

Return type:

List of psyclone.psyir.nodes.Clause

property dir_body#
Returns:

the Schedule associated with this directive.

Return type:

psyclone.psyir.nodes.Schedule

Raises:

InternalError – if this node does not have a Schedule as its first child.

class psyclone.psyir.nodes.StandaloneDirective(ast=None, children=None, parent=None, annotations=None)[source]#

Base class for all StandaloneDirective statements. This class is designed for directives which do not have code associated with them, e.g. OpenMP’s taskwait.

All classes that generate StandaloneDirective statements (e.g. OpenMP, OpenACC, compiler-specific) inherit from this class.

Inheritance

Inheritance diagram of StandaloneDirective
property clauses: Tuple[Clause]#
Returns:

the Clauses associated with this directive.

class psyclone.psyir.nodes.ACCAtomicDirective(ast=None, children=None, parent=None)[source]#

OpenACC directive to represent that the memory accesses in the associated assignment must be performed atomically. Note that the standard supports blocks with 2 assignments but this is currently unsupported in the PSyIR.

Inheritance

Inheritance diagram of ACCAtomicDirective
begin_string()[source]#
Return type:

str

Returns:

the opening string statement of this directive.

end_string()[source]#
Return type:

str

Returns:

the ending string statement of this directive.

validate_global_constraints()[source]#

Perform validation of those global constraints that can only be done at code-generation time.

Raises:

GenerationError – if the ACCAtomicDirective associated statement does not conform to a valid OpenACC atomic operation.

class psyclone.psyir.nodes.ACCDirective[source]#

Base mixin class for all OpenACC directive statements.

This class is useful to provide a unique common ancestor to all the OpenACC directives, for instance when traversing the tree with node.walk(ACCDirective)

Note that classes inheriting from it must place the ACCDirective in front of the other Directive node sub-class, so that the Python MRO gives preference to this class’s attributes.

Inheritance

Inheritance diagram of ACCDirective
class psyclone.psyir.nodes.ACCRegionDirective(ast=None, children=None, parent=None)[source]#

Base class for all OpenACC region directive statements.

Inheritance

Inheritance diagram of ACCRegionDirective
property signatures: Tuple[Set[Signature]] | Tuple[Set[Signature], Set[Signature]]#

Returns a 1-tuple or a 2-tuple of sets depending on the working API. If a 1-tuple, the set includes both input and output signatures (whether to arrays or objects) required by the Kernel call(s) that are children of this directive. If a 2-tuple, the first entry is the set of input signatures and the second entry is the set of output signatures. The set(s) describe the quantities that must be available on the remote device (probably a GPU) before the parallel region can be begun.

Returns:

1-tuple or 2-tuple of input and output sets of variable names

validate_global_constraints()[source]#

Perform validation checks for any global constraints. This can only be done at code-generation time.

Raises:

GenerationError – if this ACCRegionDirective encloses any form of PSyData node since calls to PSyData routines within OpenACC regions are not supported.

class psyclone.psyir.nodes.ACCStandaloneDirective(ast=None, children=None, parent=None, annotations=None)[source]#

Base class for all standalone OpenACC directive statements.

Inheritance

Inheritance diagram of ACCStandaloneDirective
class psyclone.psyir.nodes.ACCDataDirective(ast=None, children=None, parent=None)[source]#

Class representing the !$ACC DATA … !$ACC END DATA directive in the PSyIR.

Inheritance

Inheritance diagram of ACCDataDirective
begin_string()[source]#
Return type:

str

Returns:

the beginning of the opening statement of this directive.

end_string()[source]#
Return type:

str

Returns:

the text for the end of this directive region.

class psyclone.psyir.nodes.ACCEnterDataDirective(children=None, parent=None, async_queue=False)[source]#

Class representing a “!$ACC enter data” OpenACC directive in an InvokeSchedule. Must be sub-classed for a particular API because the way in which fields are marked as being on the remote device is API-dependent.

Parameters:
  • children (List[Node]) – list of nodes which the directive should have as children.

  • parent (Node) – the node in the InvokeSchedule to which to add this directive as a child.

  • async_queue (Union[bool, int, DataNode]) – Enable async support and attach it to the given queue. Can use False to disable, True to enable on default stream. Int to attach to the given stream ID or use a PSyIR expression to say at runtime what stream to be used.

Raises:

TypeError – if async_queue is of the wrong type.

Inheritance

Inheritance diagram of ACCEnterDataDirective
begin_string()[source]#

Returns the beginning statement of this directive. The visitor is responsible for adding the correct directive beginning (e.g. “!$”).

Returns:

the opening statement of this directive.

Return type:

str

Raises:

GenerationError – if there are no variables to copy to the device.

data_on_device(parent)[source]#

Adds nodes into an InvokeSchedule to flag that the data required by the kernels in the data region is now on the device. The generic implementation doesn’t add any node but this can be redefined in the APIs if any infrastructure call is needed.

Parameters:

parent (Node) – the node in the InvokeSchedule to which to add nodes

lower_to_language_level()[source]#

In-place replacement of this directive concept into language level PSyIR constructs.

Return type:

Node

Returns:

the lowered version of this node.

class psyclone.psyir.nodes.ACCParallelDirective(async_queue=False, default_present=True, **kwargs)[source]#

Class representing the !$ACC PARALLEL directive of OpenACC in the PSyIR. By default it includes the DEFAULT(PRESENT) clause which means this node must either come after an EnterDataDirective or within a DataDirective.

Parameters:
  • default_present (bool) – whether this directive includes the DEFAULT(PRESENT) clause or not.

  • async_queue (Union[bool, int, DataNode]) – Enable async support and attach it to the given queue. Can use False to disable, True to enable on default stream. Int to attach to the given stream ID or use a PSyIR expression to say at runtime what stream to be used.

Inheritance

Inheritance diagram of ACCParallelDirective
begin_string()[source]#

Returns the beginning statement of this directive, i.e. “acc parallel” plus any qualifiers. The backend is responsible for adding the correct characters to mark this as a directive (e.g. “!$”).

Return type:

str

Returns:

the opening statement of this directive.

property default_present: bool#
Returns:

whether the directive includes the ‘default(present)’ clause.

end_string()[source]#
Return type:

str

Returns:

the closing statement for this directive.

property fields: List[str]#

Returns a list of the names of field objects required by the Kernel call(s) that are children of this directive.

Returns:

list of names of field arguments.

class psyclone.psyir.nodes.ACCLoopDirective(collapse=None, independent=True, sequential=False, gang=False, vector=False, **kwargs)[source]#

Class managing the creation of a ‘!$acc loop’ OpenACC directive.

Parameters:
  • collapse (int) – Number of nested loops to collapse into a single iteration space or None.

  • independent (bool) – Whether or not to add the independent clause to the loop directive.

  • sequential (bool) – whether or not to add the seq clause to the loop directive.

  • gang (bool) – whether or not to add the gang clause to the loop directive.

  • vector (bool) – whether or not to add the vector clause to the loop directive.

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

Inheritance

Inheritance diagram of ACCLoopDirective
begin_string(leading_acc=True)[source]#

Returns the opening statement of this directive, i.e. “acc loop” plus any qualifiers. If leading_acc is False then the leading “acc loop” text is not included.

Parameters:

leading_acc (bool) – whether or not to include the leading “acc loop” in the text that is returned.

Return type:

str

Returns:

the opening statement of this directive.

property collapse: int | None#
Returns:

the number of nested loops to collapse into a single iteration space for this node.

end_string()[source]#

Would return the end string for this directive but “acc loop” doesn’t have a closing directive.

Return type:

str

Returns:

empty string.

property gang: bool#
Returns:

whether or not the gang clause is added to this loop directive.

property independent: bool#

Returns whether the independent clause will be added to this loop directive.

Returns:

whether the independent clause will be added to this loop directive.

node_str(colour=True)[source]#

Returns the name of this node with (optional) control codes to generate coloured output in a terminal that supports it.

Parameters:

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

Return type:

str

Returns:

description of this node, possibly coloured.

property sequential: bool#
Returns:

whether or not the seq clause is added to this loop directive.

validate_global_constraints()[source]#

Perform validation of those global constraints that can only be done at code-generation time.

Raises:

GenerationError – if this ACCLoopDirective is not enclosed within some OpenACC parallel or kernels region and is not in a Routine that has been marked up with an ‘ACC Routine’ directive.

property vector: bool#
Returns:

whether or not the vector clause is added to this loop directive.

class psyclone.psyir.nodes.ACCKernelsDirective(children=None, parent=None, default_present=True, async_queue=False)[source]#

Class representing the !$ACC KERNELS directive in the PSyIR.

Parameters:
  • children (List[Node]) – the PSyIR nodes to be enclosed in the Kernels region and which are therefore children of this node.

  • parent (Node) – the parent of this node in the PSyIR.

  • default_present (bool) – whether or not to add the “default(present)” clause to the kernels directive.

  • async_queue (Union[bool, int, DataNode]) – Enable async support and attach it to the given queue. Can use False to disable, True to enable on default stream. Int to attach to the given stream ID or use a PSyIR expression to say at runtime what stream to be used.

Inheritance

Inheritance diagram of ACCKernelsDirective
begin_string()[source]#

Returns the beginning statement of this directive, i.e. “acc kernels …”. The backend is responsible for adding the correct directive beginning (e.g. “!$”).

Return type:

str

Returns:

the beginning statement for this directive.

property default_present: bool#
Returns:

whether the “default(present)” clause is added to the kernels directive.

end_string()[source]#

Returns the ending statement for this directive. The backend is responsible for adding the language-specific syntax that marks this as a directive.

Return type:

str

Returns:

the closing statement for this directive.

class psyclone.psyir.nodes.ACCUpdateDirective(signatures, direction, children=None, parent=None, if_present=True, async_queue=False)[source]#

Class representing the OpenACC update directive in the PSyIR. It has a direction attribute that can be set to self, host or device, the set of symbols being updated and an optional if_present clause.

Parameters:
  • signatures (Signature) – the access signature(s) that need to be synchronised with the device.

  • direction (str) – the direction of the synchronisation.

  • children (List[Node]) – list of nodes which the directive should have as children.

  • parent (Node) – the node in the InvokeSchedule to which to add this directive as a child.

  • if_present (Optional[bool]) – whether or not to include the if_present clause on the update directive (this instructs the directive to silently ignore any variables that are not on the device).

  • async_queue (Union[bool, int, DataNode]) – Enable async support and attach it to the given queue. Can use False to disable, True to enable on default stream. Int to attach to the given stream ID or use a PSyIR expression to say at runtime what stream to be used.

Inheritance

Inheritance diagram of ACCUpdateDirective
begin_string()[source]#

Returns the beginning statement of this directive, i.e. “acc update host(symbol)”. The backend is responsible for adding the correct characters to mark this as a directive (e.g. “!$”).

Return type:

str

Returns:

the opening statement of this directive.

property direction: str#
Returns:

the direction of the synchronisation.

property if_present: bool#
Returns:

whether or not to add the ‘if_present’ clause.

property sig_set: Signature#
Returns:

the set of signatures to synchronise with the device.

class psyclone.psyir.nodes.ACCRoutineDirective(parallelism='seq', **kwargs)[source]#

Class representing an “ACC routine” OpenACC directive in PSyIR.

Parameters:

parallelism (str) – the level of parallelism in the routine, one of “gang”, “seq”, “vector”, “worker”.

Inheritance

Inheritance diagram of ACCRoutineDirective
begin_string()[source]#

Returns the beginning statement of this directive, i.e. “acc routine”. The visitor is responsible for adding the correct directive beginning (e.g. “!$”).

Return type:

str

Returns:

the opening statement of this directive.

property parallelism#
Returns:

the clause describing the level of parallelism within this routine (or a called one).

Return type:

str

class psyclone.psyir.nodes.ACCCopyClause(ast=None, children=None, parent=None, annotations=None)[source]#

OpenACC copy clause. Specifies a list of variables that are to be copied to the device at the start of the associated region and back to the host at the end.

Inheritance

Inheritance diagram of ACCCopyClause
class psyclone.psyir.nodes.ACCCopyInClause(ast=None, children=None, parent=None, annotations=None)[source]#

OpenACC copy clause. Specifies a list of variables that are to be copied to the device at the start of a region.

Inheritance

Inheritance diagram of ACCCopyInClause
class psyclone.psyir.nodes.ACCCopyOutClause(ast=None, children=None, parent=None, annotations=None)[source]#

OpenACC copy clause. Specifies a list of variables that are to be copied from the device to the host at the end of the associated region.

Inheritance

Inheritance diagram of ACCCopyOutClause
class psyclone.psyir.nodes.OMPAtomicDirective(ast=None, children=None, parent=None, directive_type=None)[source]#

OpenMP directive to represent that the memory accesses in the associated assignment must be performed atomically. Note that the standard supports blocks with 2 assignments but this is currently unsupported in the PSyIR.

Parameters:
  • ast (Optional[fparser.two.Fortran2003.Base]) – the entry in the fparser2 parse tree representing the code contained within this directive or None.

  • children (List[Node]) – the nodes that will be children of this Directive node or None.

  • parent (Node) – PSyIR node that is the parent of this Directive or None.

  • directive_type (psyclone.psyir.nodes.OMPAtomicDirective.                          AtomicDirectiveType) – the directive type of the atomic operation.

Inheritance

Inheritance diagram of OMPAtomicDirective
begin_string()[source]#
Returns:

the opening string statement of this directive.

Return type:

str

end_string()[source]#
Returns:

the ending string statement of this directive.

Return type:

str

validate_global_constraints()[source]#

Perform validation of those global constraints that can only be done at code-generation time.

Raises:

GenerationError – if the OMPAtomicDirective associated statement does not conform to a valid OpenMP atomic operation.

class psyclone.psyir.nodes.OMPBarrierDirective(ast=None, children=None, parent=None, annotations=None)[source]#

Class representing an OpenMP BARRIER directive in the PSyIR.

Inheritance

Inheritance diagram of OMPBarrierDirective
begin_string()[source]#

Returns the beginning statement of this directive, i.e. “omp barrier”. The visitor is responsible for adding the correct directive beginning (e.g. “!$”).

Return type:

str

Returns:

the opening statement of this directive.

validate_global_constraints()[source]#

Perform validation checks that can only be done at code-generation time.

Raises:

GenerationError – if this OMPBarrier is not enclosed within some OpenMP parallel region.

class psyclone.psyir.nodes.OMPDirective[source]#

Base mixin class for all OpenMP-related directives.

This class is useful to provide a unique common ancestor to all the OpenMP directives, for instance when traversing the tree with node.walk(OMPDirective)

Note that classes inheriting from it must place the OMPDirective in front of the other Directive node sub-class, so that the Python MRO gives preference to this class’s attributes.

Inheritance

Inheritance diagram of OMPDirective
class psyclone.psyir.nodes.OMPRegionDirective(ast=None, children=None, parent=None)[source]#

Base class for all OpenMP region-related directives.

Inheritance

Inheritance diagram of OMPRegionDirective
class psyclone.psyir.nodes.OMPStandaloneDirective(ast=None, children=None, parent=None, annotations=None)[source]#

Base class for all OpenMP-related standalone directives.

Inheritance

Inheritance diagram of OMPStandaloneDirective
class psyclone.psyir.nodes.OMPParallelDirective(ast=None, children=None, parent=None)[source]#

Class representing an OpenMP Parallel directive.

Inheritance

Inheritance diagram of OMPParallelDirective
begin_string()[source]#

Returns the beginning statement of this directive, i.e. “omp parallel”. The visitor is responsible for adding the correct directive beginning (e.g. “!$”).

Returns:

the opening statement of this directive.

Return type:

str

classmethod create(children=None)[source]#

Create an OMPParallelDirective.

Parameters:

children (List of psyclone.psyir.nodes.Node) – The child nodes of the new directive.

Returns:

A new OMPParallelDirective.

Return type:

psyclone.psyir.nodes.OMPParallelDirective

property default_clause#
Returns:

The OMPDefaultClause associated with this Directive.

Return type:

psyclone.psyir.nodes.OMPDefaultClause

end_string()[source]#

Returns the end (or closing) statement of this directive, i.e. “omp end parallel”. The visitor is responsible for adding the correct directive beginning (e.g. “!$”).

Returns:

the end statement for this directive.

Return type:

str

infer_sharing_attributes()[source]#

The PSyIR does not specify if each symbol inside an OpenMP region is private, firstprivate, shared or shared but needs synchronisation, the attributes are inferred looking at the usage of each symbol inside the parallel region.

This method analyses the directive body and automatically classifies each symbol using the following rules: - All arrays are shared unless listed in the explicitly private list. - Scalars that are accessed only once are shared. - Scalars that are read-only or written outside a loop are shared. - Scalars written in multiple iterations of a loop are private, unless:

  • there is a write-after-read dependency in a loop iteration, in this case they are shared but need synchronisation;

  • they are read before in the same parallel region (but not inside the same loop iteration), in this case they are firstprivate.

  • they are only conditionally written in some iterations; in this case they are firstprivate.

This method returns the sets of private, firstprivate, and shared but needing synchronisation symbols, all symbols not in these sets are assumed shared. How to synchronise the symbols in the third set is up to the caller of this method.

Returns:

three set of symbols that classify each of the symbols in the directive body as PRIVATE, FIRSTPRIVATE or SHARED NEEDING SYNCHRONISATION.

Return type:

Tuple[Set(psyclone.psyir.symbols.Symbol), Set(psyclone.psyir.symbols.Symbol), Set(psyclone.psyir.symbols.Symbol)]

Raises:

GenerationError – if the DefaultClauseType associated with this OMPParallelDirective is not shared.

lower_to_language_level()[source]#

In-place construction of clauses as PSyIR constructs. At the higher level these clauses rely on dynamic variable dependence logic to decide what is private and what is shared, so we use this lowering step to find out which References are private, and place them explicitly in the lower-level tree to be processed by the backend visitor.

Returns:

the lowered version of this node.

Return type:

psyclone.psyir.node.Node

Raises:

GenerationError – if the OpenMP directive needs some synchronisation mechanism to create valid code. These are not implemented yet.

property private_clause#
Returns:

The current OMPPrivateClause associated with this Directive.

Return type:

psyclone.psyir.nodes.OMPPrivateClause

validate_global_constraints()[source]#

Perform validation checks that can only be done at code-generation time.

Raises:

GenerationError – if this OMPDoDirective is not enclosed within some OpenMP parallel region.

class psyclone.psyir.nodes.OMPSerialDirective(ast=None, children=None, parent=None)[source]#

Abstract class representing OpenMP serial regions, e.g. OpenMP SINGLE or OpenMP Master.

Inheritance

Inheritance diagram of OMPSerialDirective
lower_to_language_level()[source]#

Checks that any task dependencies inside this node are valid.

validate_global_constraints()[source]#

Perform validation checks that can only be done at code-generation time.

Raises:
  • GenerationError – if this OMPSerial is not enclosed within some OpenMP parallel region.

  • GenerationError – if this OMPSerial is enclosed within any OMPSerialDirective subclass region.

class psyclone.psyir.nodes.OMPSingleDirective(nowait=False, **kwargs)[source]#

Class representing an OpenMP SINGLE directive in the PSyIR.

Parameters:
  • nowait (bool) – argument describing whether this single should have a nowait clause applied. Default value is False.

  • kwargs (unwrapped dict.) – additional keyword arguments provided to the PSyIR node.

Inheritance

Inheritance diagram of OMPSingleDirective
begin_string()[source]#

Returns the beginning statement of this directive, i.e. “omp single”. The visitor is responsible for adding the correct directive beginning (e.g. “!$”).

Returns:

the opening statement of this directive.

Return type:

str

end_string()[source]#

Returns the end (or closing) statement of this directive, i.e. “omp end single”. The visitor is responsible for adding the correct directive beginning (e.g. “!$”).

Returns:

the end statement for this directive.

Return type:

str

property nowait#
Returns:

whether the nowait clause is specified for this directive.

Return type:

bool

class psyclone.psyir.nodes.OMPMasterDirective(ast=None, children=None, parent=None)[source]#

Class representing an OpenMP MASTER directive in the PSyclone AST.

Inheritance

Inheritance diagram of OMPMasterDirective
begin_string()[source]#

Returns the beginning statement of this directive, i.e. “omp master”. The visitor is responsible for adding the correct directive beginning (e.g. “!$”).

Returns:

the opening statement of this directive.

Return type:

str

end_string()[source]#

Returns the end (or closing) statement of this directive, i.e. “omp end master”. The visitor is responsible for adding the correct directive beginning (e.g. “!$”).

Returns:

the end statement for this directive.

Return type:

str

class psyclone.psyir.nodes.OMPTaskloopDirective(grainsize=None, num_tasks=None, nogroup=False, **kwargs)[source]#

Class representing an OpenMP TASKLOOP directive in the PSyIR.

Parameters:
  • grainsize (int or None.) – The grainsize value used to specify the grainsize clause on this OpenMP directive. If this is None the grainsize clause is not applied. Default value is None.

  • num_tasks (int or None.) – The num_tasks value used to specify the num_tasks clause on this OpenMP directive. If this is None the num_tasks clause is not applied. Default value is None.

  • nogroup (bool) – Whether the nogroup clause should be used for this node. Default value is False

  • kwargs (unwrapped dict.) – additional keyword arguments provided to the PSyIR node.

Raises:

GenerationError – if this OMPTaskloopDirective has both a grainsize and num_tasks value specified.

Inheritance

Inheritance diagram of OMPTaskloopDirective
begin_string()[source]#

Returns the beginning statement of this directive, i.e. “omp taskloop …”. The visitor is responsible for adding the correct directive beginning (e.g. “!$”).

Returns:

the beginning statement for this directive.

Return type:

str

end_string()[source]#

Returns the end (or closing) statement of this directive, i.e. “omp end taskloop”. The visitor is responsible for adding the correct directive beginning (e.g. “!$”).

Returns:

the end statement for this directive.

Return type:

str

property nogroup#
Returns:

the nogroup clause status of this node.

Return type:

bool

validate_global_constraints()[source]#

Perform validation checks that can only be done at code-generation time.

Raises:
  • GenerationError – if this OMPTaskloopDirective is not enclosed within an OpenMP serial region.

  • GenerationError – if this OMPTaskloopDirective has two Nogroup clauses as children.

class psyclone.psyir.nodes.OMPTaskDirective(children=None, parent=None, clauses=None)[source]#

Class representing an OpenMP TASK directive in the PSyIR after lowering. This node should not be created by any transformation, it is solely used to represent TASK directives after lowering a DynamicOMPTaskDirective.

Parameters:

Inheritance

Inheritance diagram of OMPTaskDirective
begin_string()[source]#

Returns the beginning statement of this directive, i.e. “omp task …”. The visitor is responsible for adding the correct directive beginning (e.g. “!$”).

Returns:

the beginning statement for this directive.

Return type:

str

end_string()[source]#

Returns the end (or closing) statement of this directive, i.e. “omp end task”. The visitor is responsible for adding the correct directive beginning (e.g. “!$”).

Returns:

the end statement for this directive.

Return type:

str

property input_depend_clause#
Returns:

the OMPDependClause child of this node corresponding to input dependencies.

Return type:

psyclones.psyir.nodes.OMPDependClause

property output_depend_clause#
Returns:

the OMPDependClause child of this node corresponding to output dependencies.

Return type:

psyclones.psyir.nodes.OMPDependClause

validate_global_constraints()[source]#

Perform validation checks that can only be done at code-generation time.

Raises:

GenerationError – if this OMPTaskDirective is not enclosed within an OpenMP serial region.

class psyclone.psyir.nodes.DynamicOMPTaskDirective(children=None, parent=None)[source]#

Class representing an OpenMP TASK directive in the PSyIR.

Parameters:
  • children (list) – list of Nodes that are children of this Node.

  • parent (psyclone.psyir.nodes.Node) – the Node in the AST that has this directive as a child

Inheritance

Inheritance diagram of DynamicOMPTaskDirective
lower_to_language_level()[source]#

Lowers the structure of the PSyIR tree inside the Directive to generate the Clauses that are required for this Directive.

class psyclone.psyir.nodes.OMPDoDirective(omp_schedule='none', collapse=None, reprod=None, nowait=False, **kwargs)[source]#

Class representing an OpenMP DO directive in the PSyIR.

Parameters:
  • omp_schedule (Optional[str]) – the OpenMP schedule to use. Defaults to “none” which means it is implementation dependent.

  • collapse (Optional[int]) – optional number of nested loops to collapse into a single iteration space to parallelise. Defaults to None.

  • reprod (Optional[bool]) – whether or not to generate code for run-reproducible OpenMP reductions (if not specified the value is provided by the PSyclone Config file).

  • nowait (bool) – whether or not to add a nowait clause onto this directive. Default is False.

  • kwargs (unwrapped dict.) – additional keyword arguments provided to the PSyIR node.

Inheritance

Inheritance diagram of OMPDoDirective
begin_string()[source]#

Returns the beginning statement of this directive, i.e. “omp do …”. The visitor is responsible for adding the correct directive beginning (e.g. “!$”).

Returns:

the beginning statement for this directive.

Return type:

str

property collapse#
Returns:

the value of the collapse clause.

Return type:

int or NoneType

end_string()[source]#

Returns the end (or closing) statement of this directive, i.e. “omp end do”. The visitor is responsible for adding the correct directive beginning (e.g. “!$”).

Returns:

the end statement for this directive.

Return type:

str

lower_to_language_level()[source]#

In-place construction of clauses as PSyIR constructs. The clauses here may need to be updated if code has changed, or be added if not yet present.

Returns:

the lowered version of this node.

Return type:

psyclone.psyir.node.Node

node_str(colour=True)[source]#

Returns the name of this node with (optional) control codes to generate coloured output in a terminal that supports it.

Parameters:

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

Returns:

description of this node, possibly coloured.

Return type:

str

property nowait: bool#
Returns:

whether this directive has a nowait clause.

property omp_schedule#
Returns:

the omp_schedule for this object.

Return type:

str

property reprod#
Returns:

whether reprod has been set for this object or not.

validate_global_constraints()[source]#

Perform validation checks that can only be done at code-generation time.

Raises:

GenerationError – if this OMPDoDirective is not enclosed within some OpenMP parallel region.

class psyclone.psyir.nodes.OMPParallelDoDirective(**kwargs)[source]#

Class for the !$OMP PARALLEL DO directive. This inherits from both OMPParallelDirective (because it creates a new OpenMP thread-parallel region) and OMPDoDirective (because it causes a loop to be parallelised).

Parameters:

kwargs (unwrapped dict.) – additional keyword arguments provided to the PSyIR node.

Inheritance

Inheritance diagram of OMPParallelDoDirective
begin_string()[source]#

Returns the beginning statement of this directive, i.e. “omp parallel do …”. The visitor is responsible for adding the correct directive beginning (e.g. “!$”).

Returns:

the beginning statement for this directive.

Return type:

str

classmethod create(children=None, **kwargs)[source]#

Create an OMPParallelDoDirective.

Parameters:
  • children (List of psyclone.psyir.nodes.Node) – The child nodes of the new directive.

  • kwargs (unwrapped dict.) – additional keyword arguments provided to the PSyIR node.

Returns:

A new OMPParallelDoDirective.

Return type:

psyclone.psyir.nodes.OMPParallelDoDirective

end_string()[source]#

Returns the end (or closing) statement of this directive, i.e. “omp end parallel do”. The visitor is responsible for adding the correct directive beginning (e.g. “!$”).

Returns:

the end statement for this directive.

Return type:

str

lower_to_language_level()[source]#

In-place construction of clauses as PSyIR constructs. The clauses here may need to be updated if code has changed, or be added if not yet present.

Returns:

the lowered version of this node.

Return type:

psyclone.psyir.node.Node

validate_global_constraints()[source]#

Perform validation checks that can only be done at code-generation time.

class psyclone.psyir.nodes.OMPTaskwaitDirective(ast=None, children=None, parent=None, annotations=None)[source]#

Class representing an OpenMP TASKWAIT directive in the PSyIR.

Inheritance

Inheritance diagram of OMPTaskwaitDirective
begin_string()[source]#

Returns the beginning statement of this directive, i.e. “omp taskwait”. The visitor is responsible for adding the correct directive beginning (e.g. “!$”).

Returns:

the opening statement of this directive.

class psyclone.psyir.nodes.OMPTargetDirective(nowait=False, **kwargs)[source]#

Class for the !$OMP TARGET directive that offloads the code contained in its region into an accelerator device.

Parameters:

nowait (bool) – whether or not to add a nowait clause onto this directive. Default is False.

Inheritance

Inheritance diagram of OMPTargetDirective
begin_string()[source]#

Returns the beginning statement of this directive, i.e. “omp target”. The visitor is responsible for adding the correct directive beginning (e.g. “!$”).

Returns:

the opening statement of this directive.

Return type:

str

end_string()[source]#

Returns the end (or closing) statement of this directive, i.e. “omp end target”. The visitor is responsible for adding the correct directive beginning (e.g. “!$”).

Returns:

the end statement for this directive.

Return type:

str

property nowait: bool#
Returns:

whether this directive has a nowait clause.

class psyclone.psyir.nodes.OMPLoopDirective(collapse=None, nowait=False, **kwargs)[source]#

Class for the !$OMP LOOP directive that specifies that the iterations of the associated loops may execute concurrently.

Parameters:
  • collapse (Optional[int]) – optional number of nested loops to collapse into a single iteration space to parallelise. Defaults to None.

  • nowait (bool) – whether or not to add a nowait clause onto this directive. Default is False.

  • kwargs (unwrapped dict.) – additional keyword arguments provided to the PSyIR node.

Inheritance

Inheritance diagram of OMPLoopDirective
begin_string()[source]#

Returns the beginning statement of this directive, i.e. “omp loop”. The visitor is responsible for adding the correct directive beginning (e.g. “!$”).

Returns:

the opening statement of this directive.

Return type:

str

property collapse#
Returns:

the value of the collapse clause.

Return type:

int or NoneType

end_string()[source]#

Returns the end (or closing) statement of this directive, i.e. “omp end loop”. The visitor is responsible for adding the correct directive beginning (e.g. “!$”).

Returns:

the end statement for this directive.

Return type:

str

node_str(colour=True)[source]#

Returns the name of this node with (optional) control codes to generate coloured output in a terminal that supports it.

Parameters:

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

Returns:

description of this node, possibly coloured.

Return type:

str

property nowait: bool#
Returns:

whether this directive has a nowait clause.

validate_global_constraints()[source]#

Perform validation of those global constraints that can only be done at code-generation time.

Raises:
  • GenerationError – if this OMPLoopDirective has more than one child in its associated schedule.

  • GenerationError – if the schedule associated with this OMPLoopDirective does not contain a Loop.

  • GenerationError – this directive must be inside a omp target or parallel region.

  • GenerationError – if this OMPLoopDirective has a collapse clause but it doesn’t have the expected number of nested Loops.

class psyclone.psyir.nodes.OMPDeclareTargetDirective(ast=None, children=None, parent=None, annotations=None)[source]#

Class representing an OpenMP Declare Target directive in the PSyIR.

Inheritance

Inheritance diagram of OMPDeclareTargetDirective
begin_string()[source]#

Returns the beginning statement of this directive, i.e. “omp routine”. The visitor is responsible for adding the correct directive beginning (e.g. “!$”).

Returns:

the opening statement of this directive.

Return type:

str

validate_global_constraints()[source]#

Perform validation checks that can only be done at code-generation time.

Raises:

GenerationError – if this directive is not the first statement in a routine.

class psyclone.psyir.nodes.OMPSimdDirective(ast=None, children=None, parent=None)[source]#

OpenMP directive to inform that the associated loop can be vectorised.

Inheritance

Inheritance diagram of OMPSimdDirective
begin_string()[source]#
Returns:

the opening string statement of this directive.

Return type:

str

end_string()[source]#
Returns:

the ending string statement of this directive.

Return type:

str

validate_global_constraints()[source]#

Perform validation of those global constraints that can only be done at code-generation time.

Raises:

GenerationError – if the OMPSimdDirective does not contain precisely one loop.

class psyclone.psyir.nodes.OMPTeamsDistributeParallelDoDirective(**kwargs)[source]#

Class representing the OMP teams distribute parallel do directive.

Inheritance

Inheritance diagram of OMPTeamsDistributeParallelDoDirective
class psyclone.psyir.nodes.OMPTeamsLoopDirective(**kwargs)[source]#

Class representing the OMP teams loop directive.

Inheritance

Inheritance diagram of OMPTeamsLoopDirective
class psyclone.psyir.nodes.OMPGrainsizeClause(ast=None, children=None, parent=None, annotations=None)[source]#

OpenMP grainsize clause, used by OMPTaskloopDirective. Controls the grainsize of the associated directive.

Inheritance

Inheritance diagram of OMPGrainsizeClause
class psyclone.psyir.nodes.OMPNogroupClause(ast=None, children=None, parent=None, annotations=None)[source]#

OpenMP nogroup clause, used by OMPTaskloopDirective to disable the implicit Taskgroup associated with a Taskloop.

Inheritance

Inheritance diagram of OMPNogroupClause
class psyclone.psyir.nodes.OMPNowaitClause(ast=None, children=None, parent=None, annotations=None)[source]#

OpenMP nowait clause. Disable the implicit barrier at the end of the associated directive.

Inheritance

Inheritance diagram of OMPNowaitClause
class psyclone.psyir.nodes.OMPNumTasksClause(ast=None, children=None, parent=None, annotations=None)[source]#

OpenMP numtasks clause, used by OMPTaskloopDirective. Controls the number of tasks created by OpenMP for the associated directive.

Inheritance

Inheritance diagram of OMPNumTasksClause
class psyclone.psyir.nodes.OMPPrivateClause(ast=None, children=None, parent=None, annotations=None)[source]#

OpenMP private clause. This is used to declare variables as private to an OpenMP region.

Inheritance

Inheritance diagram of OMPPrivateClause
static create(symbols)[source]#

Create a OMPPrivateClause containing a Reference to each of the provided symbols as children.

Parameters:

symbols (List[psyclone.psyir.symbols.Symbol]) – List of symbols to reference in the private clause.

Returns:

A OMPPrivateClause referencing the provided symbols.

Return type:

py:class:psyclone.psyir.nodes.OMPPrivateClause

Raises:

TypeError – If the symbols argument is not a List that contains only PSyIR Symbols.

class psyclone.psyir.nodes.OMPDefaultClause(clause_type=DefaultClauseTypes.SHARED, **kwargs)[source]#

OpenMP Default clause. Used to determine the default declaration for variables used in an OpenMP region.

Parameters:
  • clause_type (DefaultClauseTypes) – The default data-sharing attribute to be described by this clause. The default value is OMPDefaultClause.DefaultClauseTypes.SHARED.

  • kwargs (unwrapped dict.) – additional keyword arguments provided to the PSyIR node.

Raises:

TypeError – if the supplied clause_type is not the correct type.

Inheritance

Inheritance diagram of OMPDefaultClause
class DefaultClauseTypes(*values)[source]#

Enumeration of the different types of OMPDefaultClause supported in PSyclone.

property clause_type: DefaultClauseTypes#

Gets the clause type value of this OMPDefaultClause

Returns:

the clause type for this OMPDefaultClause.

node_str(colour=True)[source]#
Parameters:

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

Return type:

str

Returns:

a text description of this node.

class psyclone.psyir.nodes.OMPReductionClause(operator, **kwargs)[source]#

OpenMP Reduction clause.

Parameters:
  • operator (ReductionClauseTypes) – The reduction operator to use for this clause.

  • kwargs (unwrapped dict.) – additional keyword arguments provided to the PSyIR node.

Raises:

TypeError – if the supplied operator argument is the wrong type.

Inheritance

Inheritance diagram of OMPReductionClause
class ReductionClauseTypes(*values)[source]#

Enumeration of the different operators for OMPReductionClause supported in PSyclone.

node_str(colour=True)[source]#
Parameters:

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

Return type:

str

Returns:

a text description of this node.

property operator: ReductionClauseTypes#
Returns:

the operator of this clause.

class psyclone.psyir.nodes.OMPScheduleClause(schedule='none', **kwargs)[source]#

OpenMP Schedule clause used for OMP Do Directives.

Parameters:
  • schedule (str) – The OpenMP schedule to use with this directive. The default value is “none” which means that no explicit schedule is specified.

  • kwargs (unwrapped dict.) – additional keyword arguments provided to the PSyIR node.

Inheritance

Inheritance diagram of OMPScheduleClause
node_str(colour=True)[source]#
Parameters:

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

Return type:

str

Returns:

a text description of this node.

property schedule: str#
Returns:

the schedule for this OMPScheduleClause.

class psyclone.psyir.nodes.OMPFirstprivateClause(ast=None, children=None, parent=None, annotations=None)[source]#

OpenMP firstprivate clause. This is used to declare variables as firstprivate to an OpenMP region.

Inheritance

Inheritance diagram of OMPFirstprivateClause
static create(symbols)[source]#

Create an OMPFirstprivateClause containing a Reference to each of the provided symbols as children.

Parameters:

symbols (List[psyclone.psyir.symbols.Symbol]) – List of symbols to reference in the firstprivate clause.

Returns:

A OMPFirstprivateClause referencing the provided symbols.

Return type:

py:class:psyclone.psyir.nodes.OMPFirstprivateClause

Raises:

TypeError – If the symbols argument is not a List that contains only PSyIR Symbols.

class psyclone.psyir.nodes.OMPSharedClause(ast=None, children=None, parent=None, annotations=None)[source]#

OpenMP shared clause. This is used to declare variables as shared in an OpenMP region.

Inheritance

Inheritance diagram of OMPSharedClause
class psyclone.psyir.nodes.OMPDependClause(depend_type=DependClauseTypes.INOUT, **kwargs)[source]#

OpenMP Depend clause used for OpenMP Task directives.

Parameters:
  • depend_type (DependClauseTypes) – The dependency type to use for this clause. The default value is OMPDependClause.DependClauseTypes.INOUT.

  • kwargs (unwrapped dict.) – additional keyword arguments provided to the PSyIR node.

Raises:

TypeError – if the supplied depend_type argument is the wrong type.

Inheritance

Inheritance diagram of OMPDependClause
class DependClauseTypes(*values)[source]#

Enumeration of the different types of OMPDependClause supported in PSyclone.

node_str(colour=True)[source]#
Parameters:

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

Return type:

str

Returns:

a text description of this node.

property operator: DependClauseTypes#
Returns:

the operator of this clause.

Exceptions#

exception psyclone.psyir.nodes.CallMatchingArgumentsNotFound(value)[source]#

Exception to signal that matching arguments have not been found for this routine

Inheritance

Inheritance diagram of CallMatchingArgumentsNotFound