loki.ir.nodes.internal_nodes
Intermediate node classes for nested node definitions in the Loki IR.
Classes
|
Internal representation of a code region in which names are associated with expressions or variables. |
|
Internal representation of a conditional branching construct. |
|
Internal representation of a Fortran interface block. |
|
Internal representation of a loop with induction variable and range. |
|
Internal representation of a block of code defined by two matching pragmas. |
|
Internal representation of a single code region. |
|
Internal representation of a while loop in source code. |
- class Section(body: Tuple[Node | Scope, ...] = (), source: Source | str | None = None, label: str | None = None)
Bases:
InternalNode,_SectionBaseInternal representation of a single code region.
- append(node)
Append the given node(s) to the section’s body.
- insert(pos, node)
Insert the given node(s) into the section’s body at a specific position.
- 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,_AssociateBaseInternal 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 appearssymbol_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.OrderedDictof associated expressions.
- property inverse_map
An
collections.OrderedDictof associated expressions.
- property variables
Return the variables defined in this
ScopedNode.
- 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,_LoopBaseInternal 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 defaultPragmanodes appear as standalone nodes in the IR before theLoopnode. Only a bespoke context created bypragmas_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
CONTINUEstatement (which we retain as anIntrinsicnode) and thereforeEND DOcan be omitted. For string reproducibility this parameter can be set False to indicate that this loop did not have anEND DOstatement 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,_WhileLoopBaseInternal representation of a while loop in source code.
Importantly, this is different from a
DO(Fortran) orfor(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 defaultPragmanodes appear as standalone nodes in the IR before theLoopnode. Only a bespoke context created bypragmas_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
CONTINUEstatement (which we retain as anIntrinsicnode) and thereforeEND DOcan be omitted. For string reproducibility this parameter can be set False to indicate that this loop did not have anEND DOstatement 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,_ConditionalBaseInternal 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
IFstatement and it does not have anelse_body.has_elseif (bool, optional) – Flag that indicates that this conditional has an
ELSE IFbranch in the original source. In Loki’s IR these are represented as a chain ofConditionalbut 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 ensure_tuple(value)
- property else_bodies
Return all nested node tuples in the
ELSEIF/ELSEpart of the conditional chain.
- class PragmaRegion(body: Tuple[Node | Scope, ...] = (), pragma: Node = None, pragma_post: Node = None, source: Source | str | None = None, label: str | None = None)
Bases:
InternalNode,_PragmaRegionBaseInternal 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:
- 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,_InterfaceBaseInternal 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