loki.ir.nodes

Control flow node classes for Control flow tree

Classes

Allocation(variables[, data_source, ...])

Internal representation of a variable allocation.

Assignment(lhs, rhs[, ptr, comment, source, ...])

Internal representation of a variable assignment.

Associate(associations[, body, source, ...])

Internal representation of a code region in which names are associated with expressions or variables.

CallStatement(name[, arguments, ...])

Internal representation of a subroutine call.

Comment(text[, source, label])

Internal representation of a single comment.

CommentBlock(comments[, source, label])

Internal representation of a block comment that is formed from multiple single-line comments.

Conditional(condition[, body, else_body, ...])

Internal representation of a conditional branching construct.

ConditionalAssignment([lhs, condition, rhs, ...])

Internal representation of an inline conditional assignment using a ternary operator.

DataDeclaration(variable, values[, source, ...])

Internal representation of a DATA declaration for explicit array value lists.

Deallocation(variables[, status_var, ...])

Internal representation of a variable deallocation.

Enumeration(symbols[, source, label])

Internal representation of an ENUM

Forall(named_bounds[, body, mask, name, ...])

Internal representation of a FORALL statement or construct.

Import(module[, symbols, nature, c_import, ...])

Internal representation of an import.

Interface([body, abstract, spec, source, label])

Internal representation of a Fortran interface block.

InternalNode([body, source, label])

Internal representation of a control flow node that has a traversable body property.

Intrinsic(text[, source, label])

Catch-all generic node for corner-cases.

LeafNode([source, label])

Internal representation of a control flow node without a body.

Loop(variable, bounds[, body, pragma, ...])

Internal representation of a loop with induction variable and range.

MaskedStatement(conditions, bodies[, ...])

Internal representation of a masked array assignment (WHERE clause).

MultiConditional(expr, values, bodies, else_body)

Internal representation of a multi-value conditional (eg.

Node([source, label])

Base class for all node types in Loki's internal representation.

Nullify(variables[, source, label])

Internal representation of a pointer nullification.

Pragma(keyword[, content, source, label])

Internal representation of a pragma.

PragmaRegion([body, pragma, pragma_post, ...])

Internal representation of a block of code defined by two matching pragmas.

PreprocessorDirective([text, source, label])

Internal representation of a preprocessor directive.

ProcedureDeclaration(symbols[, interface, ...])

Internal representation of a procedure declaration.

RawSource(text[, source, label])

Generic node for unparsed source code sections

ScopedNode([parent])

Mix-in to attache a scope to an IR Node

Section([body, source, label])

Internal representation of a single code region.

StatementFunction(variable, arguments, rhs, ...)

Internal representation of Fortran statement function statements

TypeDef([name, body, abstract, extends, ...])

Internal representation of a derived type definition.

VariableDeclaration(symbols[, dimensions, ...])

Internal representation of a variable declaration.

WhileLoop(condition[, body, pragma, ...])

Internal representation of a while loop in source code.

class Node(source: Source | str | None = None, label: str | None = None)

Bases: object

Base class for all node types in Loki’s internal representation.

Provides the common functionality shared by all node types; specifically, this comprises functionality to update or rebuild a node, and source metadata.

traversable

The traversable fields of the Node; that is, fields walked over by a Visitor. All arguments in __init__() whose name appear in this list are treated as traversable fields.

Type:

list of str

Parameters:
  • source (Source, optional) – the information about the original source for the Node.

  • label (str, optional) – the label assigned to the statement in the original source corresponding to the Node.

source: Source | str | None = None
label: str | None = None
property children

The traversable children of the node.

clone(*args, **kwargs)

Rebuild the node.

Constructs an identical copy of the node from when it was first created. Optionally, some or all of the arguments for it can be overwritten.

Parameters:
  • *args (optional) – The traversable arguments used to create the node. By default, args are used.

  • **kwargs (optional) – The non-traversable arguments used to create the node, By default, args_frozen are used.

property args

Arguments used to construct the Node.

property args_frozen

Arguments used to construct the Node that cannot be traversed.

view()

Pretty-print the node hierachy under this node.

ir_graph(show_comments=False, show_expressions=False, linewidth=40, symgen=<class 'str'>)

Get the IR graph to visualize the node hierachy under this node.

property live_symbols

Yield the list of live symbols at this node, i.e., variables that have been defined (potentially) prior to this point in the control flow graph.

This property is attached to the Node by loki.analyse.analyse_dataflow.attach_dataflow_analysis() or when using the loki.analyse.analyse_dataflow.dataflow_analysis_attached() context manager.

property defines_symbols

Yield the list of symbols (potentially) defined by this node.

This property is attached to the Node by loki.analyse.analyse_dataflow.attach_dataflow_analysis() or when using the loki.analyse.analyse_dataflow.dataflow_analysis_attached() context manager.

property uses_symbols

Yield the list of symbols used by this node before defining it.

This property is attached to the Node by loki.analyse.analyse_dataflow.attach_dataflow_analysis() or when using the loki.analyse.analyse_dataflow.dataflow_analysis_attached() context manager.

class InternalNode(body: Tuple[Node | Scope, ...] = (), source: Source | str | None = None, label: str | None = None)

Bases: Node, _InternalNode

Internal representation of a control flow node that has a traversable body property.

Parameters:

body (tuple) – The nodes that make up the body.

classmethod pre_init(values)

Ensure non-nested tuples for body.

class LeafNode(source: Source | str | None = None, label: str | None = None)

Bases: Node

Internal representation of a control flow node without a body.

class ScopedNode(parent: dataclasses.InitVar[object] | None = None)

Bases: Scope

Mix-in to attache a scope to an IR Node

Additionally, this specializes the node’s _update() and _rebuild() methods to make sure that an existing symbol table is carried over correctly.

property args

Arguments used to construct the ScopedNode, excluding the symbol table.

class Section(body: Tuple[Node | Scope, ...] = (), source: Source | str | None = None, label: str | None = None)

Bases: InternalNode, _SectionBase

Internal representation of a single code region.

append(node)

Append the given node(s) to the section’s body.

Parameters:

node (Node or tuple of Node) – The node(s) to append to the section.

insert(pos, node)

Insert the given node(s) into the section’s body at a specific position.

Parameters:
  • pos (int) – The position at which the node(s) should be inserted. Any existing nodes at this or after this position are shifted back.

  • node (Node or tuple of Node) – The node(s) to append to the section.

prepend(node)

Insert the given node(s) at the beginning of the section’s body.

Parameters:

node (Node or tuple of Node) – The node(s) to insert into the section.

class Associate(associations: Tuple[Tuple[Expression, Expression], ...], body: Tuple[Node | Scope, ...] = (), source: Source | str | None = None, label: str | None = None, parent: dataclasses.InitVar[object] = None)

Bases: ScopedNode, Section, _AssociateBase

Internal representation of a code region in which names are associated with expressions or variables.

Parameters:
  • body (tuple) – The associate’s body.

  • associations (dict or collections.OrderedDict) – The mapping of names to expressions or variables valid inside the associate’s body.

  • parent (Scope, optional) – The parent scope in which the associate appears

  • symbol_attrs (SymbolTable, optional) – An existing symbol table to use

  • **kwargs (optional) – Other parameters that are passed on to the parent class constructor.

property association_map

An collections.OrderedDict of associated expressions.

property variables
class Loop(variable: Expression, bounds: Expression, body: Tuple[Node | Scope, ...] = (), pragma: Tuple[Node, ...] | None = None, pragma_post: Tuple[Node, ...] | None = None, loop_label: Any | None = None, name: str | None = None, has_end_do: bool | None = True, source: Source | str | None = None, label: str | None = None)

Bases: InternalNode, _LoopBase

Internal representation of a loop with induction variable and range.

Parameters:
  • variable (Scalar) – The induction variable of the loop.

  • bounds (LoopRange) – The range of the loop, defining the iteration space.

  • body (tuple) – The loop body.

  • pragma (tuple of Pragma, optional) – Pragma(s) that appear in front of the loop. By default Pragma nodes appear as standalone nodes in the IR before the Loop node. Only a bespoke context created by pragmas_attached() attaches them for convenience.

  • pragma_post (tuple of Pragma, optional) – Pragma(s) that appear after the loop. The same applies as for pragma.

  • loop_label (str, optional) – The Fortran label for that loop. Importantly, this is an intrinsic Fortran feature and different from the statement label that can be attached to other nodes.

  • name (str, optional) – The Fortran construct name for that loop.

  • has_end_do (bool, optional) – In Fortran, loop blocks can be closed off by a CONTINUE statement (which we retain as an Intrinsic node) and therefore END DO can be omitted. For string reproducibility this parameter can be set False to indicate that this loop did not have an END DO statement in the original source.

  • **kwargs (optional) – Other parameters that are passed on to the parent class constructor.

class WhileLoop(condition: Expression | None, body: Tuple[Node | Scope, ...] = (), pragma: Node | None = None, pragma_post: Node | None = None, loop_label: Any | None = None, name: str | None = None, has_end_do: bool | None = True, source: Source | str | None = None, label: str | None = None)

Bases: InternalNode, _WhileLoopBase

Internal representation of a while loop in source code.

Importantly, this is different from a DO (Fortran) or for (C) loop, as we do not have a specified induction variable with explicit iteration range.

Parameters:
  • condition (pymbolic.primitives.Expression) – The condition evaluated before executing the loop body.

  • body (tuple) – The loop body.

  • pragma (tuple of Pragma, optional) – Pragma(s) that appear in front of the loop. By default Pragma nodes appear as standalone nodes in the IR before the Loop node. Only a bespoke context created by pragmas_attached() attaches them for convenience.

  • pragma_post (tuple of Pragma, optional) – Pragma(s) that appear after the loop. The same applies as for pragma.

  • loop_label (str, optional) – The Fortran label for that loop. Importantly, this is an intrinsic Fortran feature and different from the statement label that can be attached to other nodes.

  • name (str, optional) – The Fortran construct name for that loop.

  • has_end_do (bool, optional) – In Fortran, loop blocks can be closed off by a CONTINUE statement (which we retain as an Intrinsic node) and therefore END DO can be omitted. For string reproducibility this parameter can be set False to indicate that this loop did not have an END DO statement in the original source.

  • **kwargs (optional) – Other parameters that are passed on to the parent class constructor.

class Conditional(condition: Expression, body: Tuple[Node | Scope, ...] = (), else_body: Tuple[Node, ...] | None = (), inline: bool = False, has_elseif: bool = False, name: str | None = None, source: Source | str | None = None, label: str | None = None)

Bases: InternalNode, _ConditionalBase

Internal representation of a conditional branching construct.

Parameters:
  • condition (pymbolic.primitives.Expression) – The condition evaluated before executing the body.

  • body (tuple) – The conditional’s body.

  • else_body (tuple) – The body of the else branch. Can be empty.

  • inline (bool, optional) – Flag that marks this conditional as inline, i.e., it s body consists only of a single statement that appeared immediately after the IF statement and it does not have an else_body.

  • has_elseif (bool, optional) – Flag that indicates that this conditional has an ELSE IF branch in the original source. In Loki’s IR these are represented as a chain of Conditional but for string reproducibility this flag can be provided to enable backends to reproduce the original appearance.

  • name (str, optional) – The Fortran construct name for that conditional.

  • **kwargs (optional) – Other parameters that are passed on to the parent class constructor.

classmethod pre_init(values)

Ensure non-nested tuples for body.

class PragmaRegion(body: Tuple[Node | Scope, ...] = (), pragma: Node = None, pragma_post: Node = None, source: Source | str | None = None, label: str | None = None)

Bases: InternalNode, _PragmaRegionBase

Internal representation of a block of code defined by two matching pragmas.

Generally, the pair of pragmas are assumed to be of the form !$<keyword> <marker> and !$<keyword> end <marker>.

This node type is injected into the IR within a context created by pragma_regions_attached().

Parameters:
  • body (tuple) – The statements appearing between opening and closing pragma.

  • pragma (Pragma) – The opening pragma declaring that region.

  • pragma_post (Pragma) – The closing pragma for that region.

  • **kwargs (optional) – Other parameters that are passed on to the parent class constructor.

append(node)
insert(pos, node)

Insert at given position

prepend(node)
class Interface(body: Tuple[Node | Scope, ...] = (), abstract: bool = False, spec: Expression | str | None = None, source: Source | str | None = None, label: str | None = None)

Bases: InternalNode, _InterfaceBase

Internal representation of a Fortran interface block.

Parameters:
  • body (tuple) – The body of the interface block, containing function and subroutine specifications or procedure statements

  • abstract (bool, optional) – Flag to indicate that this is an abstract interface

  • spec (str, optional) – A generic name, operator, assignment, or I/O specification

  • **kwargs (optional) – Other parameters that are passed on to the parent class constructor.

property symbols

The list of symbol names declared by this interface

property symbol_map

Map symbol name to symbol declared by this interface

class Assignment(lhs: Expression, rhs: Expression, ptr: bool = False, comment: Node | None = None, source: Source | str | None = None, label: str | None = None)

Bases: LeafNode, _AssignmentBase

Internal representation of a variable assignment.

Parameters:
  • lhs (pymbolic.primitives.Expression) – The left-hand side of the assignment.

  • rhs (pymbolic.primitives.Expression) – The right-hand side expression of the assignment.

  • ptr (bool, optional) – Flag to indicate pointer assignment (=>). Defaults to False.

  • comment (Comment, optional) – Inline comment that appears in-line after the right-hand side in the original source.

  • **kwargs (optional) – Other parameters that are passed on to the parent class constructor.

class ConditionalAssignment(lhs: Expression | None = None, condition: Expression | None = None, rhs: Expression | None = None, else_rhs: Expression | None = None, source: Source | str | None = None, label: str | None = None)

Bases: LeafNode, _ConditionalAssignmentBase

Internal representation of an inline conditional assignment using a ternary operator.

There is no Fortran-equivalent to this. In C, this takes the following form:

lhs = condition ? rhs : else_rhs;
Parameters:
class CallStatement(name: Expression, arguments: Tuple[Expression, ...] | None = None, kwarguments: Tuple[Tuple[str, Expression], ...] | None = None, pragma: Tuple[Node, ...] | None = None, not_active: bool | None = None, chevron: Tuple[Expression, ...] | None = None, source: Source | str | None = None, label: str | None = None)

Bases: LeafNode, _CallStatementBase

Internal representation of a subroutine call.

Parameters:
  • name (pymbolic.primitives.Expression) – The name of the subroutine to call.

  • arguments (tuple of pymbolic.primitives.Expression) – The list of positional arguments.

  • kwarguments (tuple of tuple) – The list of keyword arguments, provided as pairs of (name, value).

  • pragma (tuple of Pragma, optional) – Pragma(s) that appear in front of the statement. By default Pragma nodes appear as standalone nodes in the IR before. Only a bespoke context created by pragmas_attached() attaches them for convenience.

  • not_active (bool, optional) – Flag to indicate that this call has explicitly been marked as inactive for the purpose of processing call trees (Default: None)

  • chevron (tuple of pymbolic.primitives.Expression) – Launch configuration for CUDA Fortran Kernels. See [CUDA Fortran programming guide](https://docs.nvidia.com/hpc-sdk/compilers/cuda-fortran-prog-guide/).

  • **kwargs (optional) – Other parameters that are passed on to the parent class constructor.

property procedure_type

The ProcedureType of the Subroutine object of the called routine

For a CallStatement node called call, this is shorthand for call.name.type.dtype.

If the procedure type object has been linked up with the corresponding Subroutine object, then it is available via call.procedure_type.procedure.

Returns:

The type of the called procedure. If the symbol type of the called routine has not been identified correctly, this may yield BasicType.DEFERRED.

Return type:

ProcedureType or BasicType.DEFERRED

property routine

The Subroutine object of the called routine

Shorthand for call.name.type.dtype.procedure

Returns:

If the ProcedureType object of the ProcedureSymbol in name is linked up to the target routine, this returns the corresponding Subroutine object, otherwise None.

Return type:

Subroutine or BasicType.DEFERRED

arg_iter()

Iterator that maps argument definitions in the target Subroutine to arguments and keyword arguments in the call.

Returns:

An iterator that traverses the mapping (arg name, call arg) for all positional and then keyword arguments.

Return type:

iterator

property arg_map

A full map of all qualified argument matches from arguments and keyword arguments.

check_kwarguments_order()

Check whether kwarguments are correctly ordered in respect to the arguments (self.routine.arguments).

sort_kwarguments()

Sort and update the kwarguments according to the order of the arguments (self.routine.arguments).

convert_kwargs_to_args()

Convert all kwarguments to arguments and update the call accordingly.

class Allocation(variables: Tuple[Expression, ...], data_source: Expression | None = None, status_var: Expression | None = None, source: Source | str | None = None, label: str | None = None)

Bases: LeafNode, _AllocationBase

Internal representation of a variable allocation.

Parameters:
class Deallocation(variables: Tuple[Expression, ...], status_var: Expression | None = None, source: Source | str | None = None, label: str | None = None)

Bases: LeafNode, _DeallocationBase

Internal representation of a variable deallocation.

Parameters:
class Nullify(variables: Tuple[Expression, ...], source: Source | str | None = None, label: str | None = None)

Bases: LeafNode, _NullifyBase

Internal representation of a pointer nullification.

Parameters:
  • variables (tuple of pymbolic.primitives.Expression) – The list of pointer variables that are nullified.

  • **kwargs (optional) – Other parameters that are passed on to the parent class constructor.

class Comment(text: str, source: Source | str | None = None, label: str | None = None)

Bases: LeafNode, _CommentBase

Internal representation of a single comment.

Parameters:
  • text (str, optional) – The content of the comment. Can be empty to represent empty lines in the original source.

  • **kwargs (optional) – Other parameters that are passed on to the parent class constructor.

class CommentBlock(comments: Tuple[Node, ...], source: Source | str | None = None, label: str | None = None)

Bases: LeafNode, _CommentBlockBase

Internal representation of a block comment that is formed from multiple single-line comments.

Parameters:
  • comments (tuple of Comment) – The individual (subsequent) comments that make up the block.

  • **kwargs (optional) – Other parameters that are passed on to the parent class constructor.

property text

The combined string of all comments in this block

class Pragma(keyword: str, content: str | None = None, source: Source | str | None = None, label: str | None = None)

Bases: LeafNode, _PragmaBase

Internal representation of a pragma.

Pragmas are assumed to appear in Fortran source code in the form of !$<keyword> <content>.

Parameters:
  • keyword (str) – The keyword of the pragma.

  • content (str, optional) – The content of the pragma after the keyword.

  • **kwargs (optional) – Other parameters that are passed on to the parent class constructor.

class PreprocessorDirective(text: str = None, source: Source | str | None = None, label: str | None = None)

Bases: LeafNode, _PreprocessorDirectiveBase

Internal representation of a preprocessor directive.

Preprocessor directives are typically assumed to start at the beginning of a line with the letter # in the original source.

Parameters:
  • text (str, optional) – The content of the directive.

  • **kwargs (optional) – Other parameters that are passed on to the parent class constructor.

class Import(module: str | None, symbols: Tuple[Expression, ...] = (), nature: str | None = None, c_import: bool = False, f_include: bool = False, f_import: bool = False, rename_list: Tuple[Any, ...] | None = None, source: Source | str | None = None, label: str | None = None)

Bases: LeafNode, _ImportBase

Internal representation of an import.

Parameters:
  • module (str) – The name of the module or header file to import from.

  • symbols (tuple of Expression or DataType, optional) – The list of names imported. Can be empty when importing all.

  • nature (str, optional) – The module nature (INTRINSIC or NON_INTRINSIC)

  • c_import (bool, optional) – Flag to indicate that this is a C-style include. Defaults to False.

  • f_include (bool, optional) – Flag to indicate that this is a preprocessor-style include in Fortran source code.

  • f_import (bool, optional) – Flag to indicate that this is a Fortran IMPORT.

  • rename_list (tuple of tuples (str, Expression), optional) – Rename list with pairs of (use name, local name) entries

  • **kwargs (optional) – Other parameters that are passed on to the parent class constructor.

class VariableDeclaration(symbols: Tuple[Expression, ...], dimensions: Tuple[Expression, ...] | None = None, comment: Node | None = None, pragma: Node | None = None, source: Source | str | None = None, label: str | None = None)

Bases: LeafNode, _VariableDeclarationBase

Internal representation of a variable declaration.

Parameters:
  • symbols (tuple of pymbolic.primitives.Expression) – The list of variables declared by this declaration.

  • dimensions (tuple of pymbolic.primitives.Expression, optional) – The declared allocation size if given as part of the declaration attributes.

  • comment (Comment, optional) – Inline comment that appears in-line after the declaration in the original source.

  • pragma (tuple of Pragma, optional) – Pragma(s) that appear before the declaration. By default Pragma nodes appear as standalone nodes in the IR. Only a bespoke context created by pragmas_attached() attaches them for convenience.

  • **kwargs (optional) – Other parameters that are passed on to the parent class constructor.

class ProcedureDeclaration(symbols: Tuple[Expression, ...], interface: Expression | DataType | None = None, external: bool = False, module: bool = False, generic: bool = False, final: bool = False, comment: Node | None = None, pragma: Tuple[Node, ...] | None = None, source: Source | str | None = None, label: str | None = None)

Bases: LeafNode, _ProcedureDeclarationBase

Internal representation of a procedure declaration.

Parameters:
  • symbols (tuple of pymbolic.primitives.Expression) – The list of procedure symbols declared by this declaration.

  • interface (pymbolic.primitives.Expression or DataType, optional) – The procedure interface of the declared procedure entity names.

  • external (bool, optional) – This is a Fortran EXTERNAL declaration.

  • module (bool, optional) – This is a Fortran MODULE PROCEDURE declaration in an interface (i.e. includes the keyword MODULE)

  • generic (bool, optional) – This is a generic binding procedure statement in a derived type.

  • final (bool, optional) – This is a declaration to mark a subroutine for clean-up of a derived type.

  • comment (Comment, optional) – Inline comment that appears in-line after the declaration in the original source.

  • pragma (tuple of Pragma, optional) – Pragma(s) that appear before the declaration. By default Pragma nodes appear as standalone nodes in the IR. Only a bespoke context created by pragmas_attached() attaches them for convenience.

  • **kwargs (optional) – Other parameters that are passed on to the parent class constructor.

class DataDeclaration(variable: Any, values: Tuple[Expression, ...], source: Source | str | None = None, label: str | None = None)

Bases: LeafNode, _DataDeclarationBase

Internal representation of a DATA declaration for explicit array value lists.

Parameters:
class StatementFunction(variable: Expression, arguments: Tuple[Expression, ...], rhs: Expression, return_type: SymbolAttributes, source: Source | str | None = None, label: str | None = None)

Bases: LeafNode, _StatementFunctionBase

Internal representation of Fortran statement function statements

Parameters:
property name
property is_function
class TypeDef(name: str | None = None, body: Tuple[Node | Scope, ...] = (), abstract: bool = False, extends: str | None = None, bind_c: bool = False, private: bool = False, public: bool = False, source: Source | str | None = None, label: str | None = None, parent: dataclasses.InitVar[object] = None)

Bases: ScopedNode, InternalNode, _TypeDefBase

Internal representation of a derived type definition.

Similar to Sourcefile, Module, and Subroutine, it forms its own scope for symbols and types. This is required to instantiate TypedSymbol instances in declarations, imports etc. without having them show up in the enclosing scope.

Parameters:
  • name (str) – The name of the type.

  • body (tuple) – The body of the type definition.

  • abstract (bool, optional) – Flag to indicate that this is an abstract type definition.

  • extends (str, optional) – The parent type name

  • bind_c (bool, optional) – Flag to indicate that this contains a BIND(C) attribute.

  • private (bool, optional) – Flag to indicate that this has been declared explicitly as PRIVATE

  • public (bool, optional) – Flag to indicate that this has been declared explicitly as PUBLIC

  • parent (Scope, optional) – The parent scope in which the type definition appears

  • symbol_attrs (SymbolTable, optional) – An existing symbol table to use

  • **kwargs (optional) – Other parameters that are passed on to the parent class constructor.

property ir
property parent_type
property declarations
property comments
property variables
property variable_map
property imported_symbols

Return the symbols imported in this typedef

property imported_symbol_map

Map of imported symbol names to objects

property interface_symbols

Return the list of symbols declared via interfaces in this unit

This returns always an empty tuple since there are no interface declarations allowed in typedefs.

property dtype

Return the DerivedType representing this type

clone(**kwargs)

Create a copy of the scope object with the option to override individual parameters

Note that this will also create a copy of the symbol table via SymbolTable.clone and force rescoping of variables, unless symbol_attrs and rescope_symbols are explicitly specified.

Parameters:

**kwargs (Any parameter from the constructor)

Returns:

The cloned scope object

Return type:

type(self)

class MultiConditional(expr: Expression, values: Tuple[Any, ...], bodies: Tuple[Any, ...], else_body: Tuple[Node, ...], name: str | None = None, source: Source | str | None = None, label: str | None = None)

Bases: LeafNode, _MultiConditionalBase

Internal representation of a multi-value conditional (eg. SELECT).

Parameters:
  • expr (pymbolic.primitives.Expression) – The expression that is evaluated to choose the appropriate case.

  • values (tuple of tuple of pymbolic.primitives.Expression) – The list of values, a tuple for each case.

  • bodies (tuple of tuple) – The corresponding bodies for each case.

  • else_body (tuple) – The body for the DEFAULT case.

  • name (str, optional) – The construct-name of the multi conditional in the original source.

  • **kwargs (optional) – Other parameters that are passed on to the parent class constructor.

class Forall(named_bounds: Tuple[Tuple[Expression, Expression], ...], body: Tuple[Node | Scope, ...] = (), mask: Expression | None = None, name: str | None = None, inline: bool = False, source: Source | str | None = None, label: str | None = None)

Bases: InternalNode, _ForallBase

Internal representation of a FORALL statement or construct.

Parameters:
  • named_bounds (tuple of pairs (<variable>, <range>) of type pymbolic.primitives.Expression) – The collection of named variables with bounds (ranges).

  • body (tuple of Node) – The collection of assignment statements, nested FORALLs, and/or comments.

  • mask (pymbolic.primitives.Expression, optional) – The condition that define the mask.

  • name (str, optional) – The name of the multi-line FORALL construct in the original source.

  • inline (bool, optional) – Flag to indicate a single-line FORALL statement.

  • **kwargs (optional) – Other parameters that are passed on to the parent class constructor.

class MaskedStatement(conditions: Tuple[Expression, ...], bodies: Tuple[Tuple[Node, ...], ...], default: Tuple[Node, ...] | None = None, inline: bool = False, source: Source | str | None = None, label: str | None = None)

Bases: LeafNode, _MaskedStatementBase

Internal representation of a masked array assignment (WHERE clause).

Parameters:
  • conditions (tuple of pymbolic.primitives.Expression) – The conditions that define the mask

  • bodies (tuple of tuple of Node) – The conditional assignment statements corresponding to each condition.

  • default (tuple of Node, optional) – The assignment statements to be executed for array entries not captured by the mask (ELSEWHERE statement).

  • inline (bool, optional) – Flag to indicate this is a one-line where-stmt

  • **kwargs (optional) – Other parameters that are passed on to the parent class constructor.

class Intrinsic(text: str, source: Source | str | None = None, label: str | None = None)

Bases: LeafNode, _IntrinsicBase

Catch-all generic node for corner-cases.

This is provided as a fallback for any statements that do not have an appropriate representation in the IR. These can either be language features for which support was not yet added, or statements that are not relevant in Loki’s scope of applications. This node retains the text of the statement in the original source as-is.

Parameters:
  • text (str) – The statement as a string.

  • **kwargs (optional) – Other parameters that are passed on to the parent class constructor.

class Enumeration(symbols: Tuple[Expression, ...], source: Source | str | None = None, label: str | None = None)

Bases: LeafNode, _EnumerationBase

Internal representation of an ENUM

The constants declared by this are represented as Variable objects with their value (if specified explicitly) stored as the initial property in the symbol’s type.

Parameters:
  • symbols (list of Expression) – The named constants declared in this enum

  • **kwargs (optional) – Other parameters that are passed on to the parent class constructor.

class RawSource(text: str, source: Source | str | None = None, label: str | None = None)

Bases: LeafNode, _RawSourceBase

Generic node for unparsed source code sections

This is used by the REGEX frontend to store unparsed code sections in the IR. Currently, they don’t serve any other purpose than making sure the entire string content of the original Fortran source is retained.

Parameters:
  • text (str) – The source code as a string.

  • **kwargs (optional) – Other parameters that are passed on to the parent class constructor.