Skip to content

off_grid_conditionals

ExtractOffGridConditionals

Bases: ScheduleNodeTransformer

Push off-grid conditional outside of their cartesian block.

This is the inverse transform of InlineOffGridConditionals.

InlineOffGridConditionals

Bases: ScheduleNodeVisitor

Push off-grid conditional inside their cartesian block, duplicating the conditional if needed.

Turning:

if a_flag == 0:
    map i, j, k:
        ...
    map i, j, k:
        ...
into
map i, j, k:
    if a_flag == 0:
        ...
map i, j, k:
    if a_flag == 0:
        ...

MergeConditionals

Bases: ScheduleNodeVisitor

Merge consecutive and equal conditionals.

Turning:

    if a_flag == 0:
        map i, j, k:
    if a_flag == 0:
        map i, j, k:
into
    if a_flag == 0:
        map i, j, k:
        map i, j, k:

or merge nested conditionals

if a_flag == 0:
    if b_flag == 0:
        map i, j, k
into
if a_flag = 0 and b_flag == 0:
    map i,j,k

Outside of user code, combination of ExtractOffGridConditionals, InlineOffGridConditionals and CartesianMapMerge can lead to this pattern.

RevertSimplifyConditional

Bases: ScheduleNodeVisitor

Reverting the SimplifyConditional based on book-keeping done during SimplyConditional transform

visit_ScheduleTreeRoot(_node)

Restore original Else.

WARNING: no check if those still exists in the tree, if merging of conditionals or any other operation happened, this will create bad stree.

SimplifyConditional

Bases: ScheduleNodeVisitor

Turn Else and ElseIf into Ifs.

The original nodes can be restored with RevertSimplifyConditional.