| 120 | |
| 121 | # requires lst be toposorted. like graph rewrite, but for lines |
| 122 | def line_rewrite(lst:list[UOp], pm:PatternMatcher, ctx=None) -> list[UOp]: |
| 123 | newlst = [] |
| 124 | replaced: dict[UOp, UOp] = {} |
| 125 | for u in lst: |
| 126 | nu = u.replace(src=tuple([replaced.get(x, x) for x in u.src])) |
| 127 | ret: tuple[UOp, list[UOp]] = cast(tuple[UOp, list[UOp]]|None, pm.rewrite(nu, ctx)) or (nu, [nu]) |
| 128 | replaced[u] = ret[0] |
| 129 | newlst.extend(ret[1]) |
| 130 | return newlst |
| 131 | |
| 132 | def do_linearize(ctx:Renderer, prg:UOp, sink:UOp) -> UOp: |
| 133 | if DEBUG >= 3 and sink.arg.applied_opts: print(f"{sink.arg.function_name:<25} opts: {sink.arg.applied_opts}") |