Dialect
Dialect dataclass
Dialect(
name: str,
stmts: list[type[Statement]] = list(),
attrs: list[type[Attribute]] = list(),
interps: dict[str, MethodTable] = dict(),
lowering: dict[str, FromPythonAST] = dict(),
rules: Rules = Rules(),
python_types: dict[tuple[str, str], "PyClass"] = dict(),
)
Dialect is a collection of statements, attributes, interpreters, lowerings, and codegen.
Example
from kirin import ir
my_dialect = ir.Dialect(name="my_dialect")
attrs class-attribute
instance-attribute
attrs: list[type[Attribute]] = field(
default_factory=list, init=True
)
A list of attributes in the dialect.
interps class-attribute
instance-attribute
interps: dict[str, MethodTable] = field(
default_factory=dict, init=True
)
A dictionary of registered method table in the dialect.
lowering class-attribute
instance-attribute
lowering: dict[str, FromPythonAST] = field(
default_factory=dict, init=True
)
A dictionary of registered python lowering implmentations in the dialect.
name instance-attribute
name: str
The name of the dialect.
rules class-attribute
instance-attribute
rules: Rules = field(default_factory=Rules, init=True)
A collection of rewrite rules for the dialect.
stmts class-attribute
instance-attribute
stmts: list[type[Statement]] = field(
default_factory=list, init=True
)
A list of statements in the dialect.
canonicalize
canonicalize(rule: type[RewriteRule]) -> type[RewriteRule]
Register a rewrite rule to the canonicalization pass.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rule | RewriteRule | The rewrite rule to register. | required |
Source code in src/kirin/ir/dialect.py
167 168 169 170 171 172 173 174 |
|
post_inference
post_inference(
rule: type[RewriteRule],
) -> type[RewriteRule]
Register a rewrite rule to the inference pass. Usually, this is used to register a rule that requires type inference to be run first.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rule | RewriteRule | The rewrite rule to register. | required |
Source code in src/kirin/ir/dialect.py
176 177 178 179 180 181 182 183 184 185 |
|
register
register(node: type | None = None, key: str | None = None)
register is a decorator to register a node to the dialect.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node | type | None | The node to register. Defaults to None. | None |
key | str | None | The key to register the node to. Defaults to None. | None |
Raises:
Type | Description |
---|---|
ValueError | If the node is not a subclass of Statement, Attribute, DialectInterpreter, FromPythonAST, or DialectEmit. |
Example
-
Register a method table for concrete interpreter (by default key="main") to the dialect:
from kirin import ir my_dialect = ir.Dialect(name="my_dialect") @my_dialect.register class MyMethodTable(ir.MethodTable): ...
-
Register a method table for the interpreter specified by
key
to the dialect:from kirin import ir my_dialect = ir.Dialect(name="my_dialect") @my_dialect.register(key="my_interp") class MyMethodTable(ir.MethodTable): ...
Source code in src/kirin/ir/dialect.py
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
|
Rules dataclass
Rules(
canonicalize: list[RewriteRule] = list(),
inference: list[RewriteRule] = list(),
)
canonicalize class-attribute
instance-attribute
canonicalize: list[RewriteRule] = field(
default_factory=list, init=True
)
A collection of rules for Canonicalize pass.
inference class-attribute
instance-attribute
inference: list[RewriteRule] = field(
default_factory=list, init=True
)
A collection of rules for Inference pass.