Abstract Syntax Tree#

Canonical Form#

Many transformations in pystencils’ backend require that their input AST is in canonical form. This means that:

  • Each symbol, constant, and expression node is annotated with a data type;

  • Each symbol has at most one declaration;

  • Each symbol that is never written to apart from its declaration has a const type; and

  • Each symbol whose type is not const has at least one non-declaring assignment.

The first requirement can be ensured by running the Typifier on each newly constructed subtree. The other three requirements are ensured by the CanonicalizeSymbols pass, which should be run first before applying any optimizing transformations.

Canonicality allows transformations to forego various checks that would otherwise be necessary to prove their legality.

API Documentation#

Inheritance Diagram#

Inheritance diagram of pystencils.backend.ast.astnode.PsAstNode, pystencils.backend.ast.structural, pystencils.backend.ast.axes, pystencils.backend.ast.expressions, pystencils.backend.ast.vector, pystencils.backend.extensions.foreign_ast

Base Classes#

PsAstNode

Base class for all nodes in the pystencils AST.

PsAstNodeChildrenMixin

Mix in with PsAstNode to use default implementations of get_children and set_child.

PsLeafMixIn

Mix-in for AST leaves.

Structural Nodes#

PsBlock

PsStatement

PsAssignment

PsDeclaration

PsLoop

PsConditional

Conditional branch

PsEmptyLeafMixIn

Mix-in marking AST leaves that can be treated as empty by the code generator, such as comments and preprocessor directives.

PsPragma

A C/C++ preprocessor pragma.

PsComment

Iteration Axes System#

PsAxisRange

Iteration range of an axis.

PsAxesCube

Hypercube of multiple iteration ranges.

PsIterationAxis

Common base class for iteration axes.

PsLoopAxis

Loop axis.

PsParallelLoopAxis

Parallel loop axis.

PsSimdAxis

Axis modelling a SIMD block.

PsGpuIndexingAxis

Common base class for GPU block+thread indexing axes.

PsGpuBlockAxis

Gpu block axis.

PsGpuThreadAxis

Gpu thread axis.

PsGpuBlockXThreadAxis

Gpu block x thread axis.

Expressions#

PsExpression

Base class for all expressions.

PsLvalue

Mix-in for all expressions that may occur as an lvalue; i.e. expressions that represent a memory location.

PsSymbolExpr

A single symbol as an expression.

PsConstantExpr

PsLiteralExpr

PsBufferAcc

Access into a PsBuffer.

PsSubscript

N-dimensional subscript into an array.

PsMemAcc

Pointer-based memory access with type-dependent offset.

PsLookup

PsCall

PsTernary

Ternary operator.

PsNumericOpTrait

Trait for operations valid only on numerical types

PsIntOpTrait

Trait for operations valid only on integer types

PsBoolOpTrait

Trait for boolean operations

PsUnOp

PsNeg

PsAddressOf

Take the address of a memory location.

PsCast

C-style type cast.

PsBinOp

PsAdd

PsSub

PsMul

PsDiv

PsIntDiv

C-like integer division (round to zero).

PsRem

C-style integer division remainder

PsLeftShift

PsRightShift

PsBitwiseAnd

PsBitwiseXor

PsBitwiseOr

PsAnd

PsOr

PsNot

PsRel

Base class for binary relational operators

PsEq

PsNe

PsGe

PsLe

PsGt

PsLt

PsArrayInitList

N-dimensional array initialization matrix.

SIMD Nodes#

PsVectorOp

Mix-in for vector operations

PsVecBroadcast

Broadcast a scalar value to N vector lanes.

PsVecMemAcc

Pointer-based vectorized memory access.

Utility#

expressions.evaluate_expression

Evaluate a pystencils backend expression tree with values assigned to symbols according to the given valuation.

dfs_preorder

Pre-Order depth-first traversal of an abstract syntax tree.

dfs_postorder

Post-Order depth-first traversal of an abstract syntax tree.

util.determine_memory_object

Return the memory object accessed by the given expression, together with its constness