Passes
passes
¶
ModulePassT = TypeVar('ModulePassT', bound='ModulePass')
module-attribute
¶
PassPipelineCallbackType = Callable[[ModulePass | None, builtin.ModuleOp, ModulePass | None], None]
module-attribute
¶
Type of callback functions that can be given to a PassPipeline The first argument of the function is the previous pass applied (if any). The second argument is the current state of the module. The third argument is the pass which is about to be applied (if any).
ModulePass
dataclass
¶
Bases: ArgSpecConvertible
A Pass is a named rewrite pass over an IR module that can accept arguments.
All passes are expected to leave the IR in a valid state after application, meaning that a call to .verify() succeeds on the whole module. In turn, all passes can expect that the IR they are applied to is in a valid state. It is not required that the IR verifies at any point while the pass is being applied.
In order to make a pass accept arguments, it must be a dataclass. Furthermore, only the following types are supported as argument types:
Base types: int | float | bool | string N-tuples of base types: tuple[int, ...], tuple[int|float, ...], tuple[int, ...] | tuple[float, ...] Top-level optional: ... | None
Pass arguments on the CLI are formatted as follows:
CLI arg Mapped to class field ------------------------- ------------------------------ my-pass{arg-1=1} arg_1: int = 1 my-pass{arg-1} arg_1: int | None = None my-pass{arg-1=1,2,3} arg_1: tuple[int, ...] = (1, 2, 3) my-pass{arg-1=true} arg_1: bool | None = True
Source code in xdsl/passes.py
name: str
class-attribute
¶
__init__() -> None
¶
apply(ctx: Context, op: builtin.ModuleOp) -> None
abstractmethod
¶
apply_to_clone(ctx: Context, op: builtin.ModuleOp) -> tuple[Context, builtin.ModuleOp]
¶
Creates deep copies of the module and the context, and returns the result of
calling apply on them.
Source code in xdsl/passes.py
from_pass_spec(spec: ArgSpec) -> Self
classmethod
¶
pipeline_pass_spec(*, include_default: bool = False) -> ArgSpec
¶
schedule_space(ctx: Context, module_op: builtin.ModuleOp) -> tuple[Self, ...]
classmethod
¶
Returns a tuple of Self that can be applied to rewrite the given module with
the given context without error.
The default implementation attempts to construct an instance with no parameters,
and run it on the module_op; if the module_op is mutated then the pass instance
is returned.
Parametrizable passes should override this implementation to provide a full
schedule space of transformations.
Source code in xdsl/passes.py
PassOptionInfo
¶
Bases: NamedTuple
The name, expected type, and default value for one option of a module pass.
Source code in xdsl/passes.py
PassPipeline
dataclass
¶
A representation of a pass pipeline, with an optional callback to be executed between each of the passes.
Source code in xdsl/passes.py
passes: tuple[ModulePass, ...]
instance-attribute
¶
These will be executed sequentially during the execution of the pipeline.
callback: PassPipelineCallbackType | None = field(default=None)
class-attribute
instance-attribute
¶
Function called in between every pass, taking the pass that just ran, the module, and the next pass.
__init__(passes: tuple[ModulePass, ...], callback: PassPipelineCallbackType | None = None) -> None
¶
apply(ctx: Context, op: builtin.ModuleOp) -> None
¶
Source code in xdsl/passes.py
parse_spec(available_passes: dict[str, Callable[[], type[ModulePass]]], spec: str, callback: PassPipelineCallbackType | None = None) -> PassPipeline
staticmethod
¶
Source code in xdsl/passes.py
get_pass_option_infos(arg: type[ModulePassT]) -> tuple[PassOptionInfo, ...]
¶
Returns the expected argument names, types, and optional expected values for options for the given pass.