LocalScope¶
- class hugr.passes.scope.LocalScope(*values)[source]¶
Bases:
PassScopeBase,EnumA PassScope that means the pass should modify the hugr only beneath the entrypoint, unless the entrypoint is the module root, in which case the pass should do nothing.
root: The entrypoint, unless that is the module root.
preserve_interface: the entrypoint, unless that is the module root
Methods
Returns the root of the subtree to be optimized by the pass, or none if the pass should do nothing.
Returns a list of nodes, in the subtree beneath root, for which the pass must preserve the observable semantics (ports, execution behaviour, linking).
Returns true if the pass should be applied recursively on the descendants of the root regions.
Return every region (every [dataflow] or [CFG] container - but excluding Module) in the Hugr to be optimized by the pass.
Returns whether the node may be modified by the pass.
Attributes
Run the pass only on the entrypoint region.
Run the pass on the entrypoint region and all its descendants.
- FLAT = 'EntrypointFlat'¶
Run the pass only on the entrypoint region.
If the entrypoint is the module root, does nothing.
The pass is allowed, but not required, to optimize descendant regions too. (For passes where it makes sense to distinguish flat from EntrypointRecursive, this is encouraged, but for many passes it does not make sense so both EntrypointXXX variants may behave the same.)
recursive: false.
- RECURSIVE = 'EntrypointRecursive'¶
Run the pass on the entrypoint region and all its descendants.
For an idempotent pass, this means that immediately rerunning the pass on any subregion (i.e. with the entrypoint set to any descendant of the current value), must have no effect.
If the entrypoint is the module root, does nothing.
recursive: true.
- in_scope(hugr: Hugr, n: Node) InScope¶
Returns whether the node may be modified by the pass.
Nodes outside the root subtree are never in scope. Nodes inside the subtree may be InScope.YES or InScope.PRESERVE_INTERFACE.
- preserve_interface(hugr: Hugr) Iterable[Node][source]¶
Returns a list of nodes, in the subtree beneath root, for which the pass must preserve the observable semantics (ports, execution behaviour, linking).
We include the Module in this list (if it is root) as these properties must be preserved (this rules out any other changes).
- recursive() bool[source]¶
Returns true if the pass should be applied recursively on the descendants of the root regions.
- regions(hugr: Hugr) Iterable[Node]¶
Return every region (every [dataflow] or [CFG] container - but excluding Module) in the Hugr to be optimized by the pass.
This computes all the regions to be optimized at once. In general, it is more efficient to traverse the Hugr incrementally starting from the PassScope.root instead.