Skip to content

Symbol Canonicalization, Loop-Invariant Code Motion, and AST Factory

Frederik Hennig requested to merge fhennig/loop-invariants into backend-rework

This MR introduces AST passes for symbol canonicalization and loop-invariant code motion, and an AST factory for more convenient creation of syntax trees..

Symbol Canonicalization The CanonicalizeSymbols pass will transform an AST into a canonical form with respect to the symbols occuring inside it:

  • Ensure each symbol has at most one declaration, by duplicating and renaming symbols that have multiple declarations
  • Add the const qualifier to the data type of any symbol that is never written to

Loop-Invariant Motion of Declarations The HoistLoopInvariantDeclarations pass moves declarations that are independent of loop iterations outside of the loop nest. For it to work, all symbols may have at most one declaration, so a CanonicalizeSymbols pass may have to be run before.

Both passes are now called by create_kernel.

AST Factory The newly added backend.kernelcreation.AstFactory exposes methods to quickly parse SymPy expressions and create loop nests, and is open to be extended in the future.

This MR also introduces various minor changes:

  • Support for augmented assignments is added to FreezeExpressions
  • Refactor FullIterationSpace.create_from_slice and the GenericCpu platform to use AstFactory
Edited by Frederik Hennig

Merge request reports