Skip to content

Commit 90b2a5d

Browse files
authored
refactor fcf unroll (#147)
this PR address a few issues in previous #130 1. this should be called unroll instead of inline because it does not inline an existing stdlib function. 2. #130 only supports the case when collection is a constant, this resolves the case when constant propagation fails (e.g `fn` is not pure) but fails when collection has a constant length but unknown (which is why this rewrite is called unroll) so now this rewrite relys on type parameter of `IList` which indicates the size of the immutable list, thus `Map` etc. can be unrolled without knowning how this list was constructed. (thanks to type inference on generics) ```python %3 = ilist.Map(%fn, %coll) # get unrolled to %v_1 = indexing.GetItem(%coll, 0) %3 = func.call(%fn, %v_0) %v_2 = indexing.GetItem(%coll, 1) %4 = func.call(%fn, %v_1) %v_3 = indexing.GetItem(%coll, 2) %5 = func.call(%fn, %v_2) ``` then in the case `%coll = ilist.New(...)` the `GetItem` inlining pass will replace getitem with the `SSAValue` referring to the element directly. cc: @kaihsin
1 parent 59b0695 commit 90b2a5d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+807
-703
lines changed

src/kirin/dialects/fcf/__init__.py

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/kirin/dialects/fcf/dialect.py

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/kirin/dialects/fcf/interp.py

Lines changed: 0 additions & 68 deletions
This file was deleted.

src/kirin/dialects/fcf/rewrite/__init__.py

Whitespace-only changes.

src/kirin/dialects/fcf/rewrite/fcfmap_inline.py

Lines changed: 0 additions & 50 deletions
This file was deleted.

src/kirin/dialects/fcf/stmts.py

Lines changed: 0 additions & 59 deletions
This file was deleted.

src/kirin/dialects/fcf/typeinfer.py

Lines changed: 0 additions & 134 deletions
This file was deleted.

src/kirin/dialects/func/stmts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ class Call(Statement):
112112
# not a fixed type here so just any
113113
callee: SSAValue = info.argument()
114114
inputs: tuple[SSAValue, ...] = info.argument()
115-
kwargs: tuple[str, ...] = info.attribute(property=True)
115+
kwargs: tuple[str, ...] = info.attribute(default_factory=lambda: (), property=True)
116116
result: ResultValue = info.result()
117117

118118
def print_impl(self, printer: Printer) -> None:
Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,21 @@
55
to Python's built-in list type.
66
"""
77

8-
from . import interp as interp, lowering as lowering, typeinfer as typeinfer
8+
from . import (
9+
interp as interp,
10+
rewrite as rewrite,
11+
lowering as lowering,
12+
typeinfer as typeinfer,
13+
)
914
from .stmts import (
1015
Map as Map,
1116
New as New,
17+
Push as Push,
1218
Scan as Scan,
13-
FoldL as FoldL,
14-
FoldR as FoldR,
19+
Foldl as Foldl,
20+
Foldr as Foldr,
1521
ForEach as ForEach,
22+
IListType as IListType,
1623
)
24+
from .runtime import IList as IList
1725
from ._dialect import dialect as dialect

0 commit comments

Comments
 (0)