Skip to content

Scf

scf

ScfFunctions dataclass

Bases: InterpreterFunctions

Source code in xdsl/interpreters/scf.py
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
@register_impls
class ScfFunctions(InterpreterFunctions):
    @impl(scf.IfOp)
    def run_if(self, interpreter: Interpreter, op: scf.IfOp, args: tuple[Any, ...]):
        (cond,) = args
        region = op.true_region if cond else op.false_region
        results = interpreter.run_ssacfg_region(region, ())
        return results

    @impl(scf.ForOp)
    def run_for(
        self, interpreter: Interpreter, op: scf.ForOp, args: PythonValues
    ) -> PythonValues:
        lb, ub, step, *loop_args = args
        loop_args = tuple(loop_args)

        for i in range(lb, ub, step):
            loop_args = interpreter.run_ssacfg_region(
                op.body, (i, *loop_args), "for_loop"
            )

        return loop_args

    @impl_terminator(scf.YieldOp)
    def run_br(self, interpreter: Interpreter, op: scf.YieldOp, args: tuple[Any, ...]):
        return ReturnedValues(args), ()

run_if(interpreter: Interpreter, op: scf.IfOp, args: tuple[Any, ...])

Source code in xdsl/interpreters/scf.py
17
18
19
20
21
22
@impl(scf.IfOp)
def run_if(self, interpreter: Interpreter, op: scf.IfOp, args: tuple[Any, ...]):
    (cond,) = args
    region = op.true_region if cond else op.false_region
    results = interpreter.run_ssacfg_region(region, ())
    return results

run_for(interpreter: Interpreter, op: scf.ForOp, args: PythonValues) -> PythonValues

Source code in xdsl/interpreters/scf.py
24
25
26
27
28
29
30
31
32
33
34
35
36
@impl(scf.ForOp)
def run_for(
    self, interpreter: Interpreter, op: scf.ForOp, args: PythonValues
) -> PythonValues:
    lb, ub, step, *loop_args = args
    loop_args = tuple(loop_args)

    for i in range(lb, ub, step):
        loop_args = interpreter.run_ssacfg_region(
            op.body, (i, *loop_args), "for_loop"
        )

    return loop_args

run_br(interpreter: Interpreter, op: scf.YieldOp, args: tuple[Any, ...])

Source code in xdsl/interpreters/scf.py
38
39
40
@impl_terminator(scf.YieldOp)
def run_br(self, interpreter: Interpreter, op: scf.YieldOp, args: tuple[Any, ...]):
    return ReturnedValues(args), ()