Skip to content

Riscv scf

riscv_scf

RiscvScfFunctions dataclass

Bases: InterpreterFunctions

Source code in xdsl/interpreters/riscv_scf.py
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
@register_impls
@dataclass
class RiscvScfFunctions(InterpreterFunctions):
    bitwidth: int = field(default=32)

    @impl(riscv_scf.ForOp)
    def run_for(
        self,
        interpreter: Interpreter,
        op: riscv_scf.ForOp,
        args: tuple[Any, ...],
    ):
        args = RiscvFunctions.get_reg_values(interpreter, op.operands, args)
        lb, ub, step, *loop_args = args
        loop_args = tuple(loop_args)

        for i in range(lb, ub, step):
            RiscvFunctions.set_reg_value(interpreter, op.body.block.args[0].type, i)
            loop_args = interpreter.run_ssacfg_region(
                op.body, (i, *loop_args), "for_loop"
            )

        return loop_args

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

    @impl(riscv_scf.WhileOp)
    def run_while(
        self,
        interpreter: Interpreter,
        op: riscv_scf.WhileOp,
        args: tuple[Any, ...],
    ):
        cond, *results = interpreter.run_ssacfg_region(
            op.before_region, args, "while_head"
        )

        while cond:
            args = interpreter.run_ssacfg_region(
                op.after_region, tuple(results), "while_body"
            )
            cond, *results = interpreter.run_ssacfg_region(
                op.before_region, args, "while_head"
            )

        return tuple(results)

    @impl_terminator(riscv_scf.ConditionOp)
    def run_condition(
        self, interpreter: Interpreter, op: riscv_scf.ConditionOp, args: tuple[Any, ...]
    ):
        return ReturnedValues(args), ()

bitwidth: int = field(default=32) class-attribute instance-attribute

__init__(bitwidth: int = 32) -> None

run_for(interpreter: Interpreter, op: riscv_scf.ForOp, args: tuple[Any, ...])

Source code in xdsl/interpreters/riscv_scf.py
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
@impl(riscv_scf.ForOp)
def run_for(
    self,
    interpreter: Interpreter,
    op: riscv_scf.ForOp,
    args: tuple[Any, ...],
):
    args = RiscvFunctions.get_reg_values(interpreter, op.operands, args)
    lb, ub, step, *loop_args = args
    loop_args = tuple(loop_args)

    for i in range(lb, ub, step):
        RiscvFunctions.set_reg_value(interpreter, op.body.block.args[0].type, i)
        loop_args = interpreter.run_ssacfg_region(
            op.body, (i, *loop_args), "for_loop"
        )

    return loop_args

run_yield(interpreter: Interpreter, op: riscv_scf.YieldOp, args: tuple[Any, ...])

Source code in xdsl/interpreters/riscv_scf.py
40
41
42
43
44
@impl_terminator(riscv_scf.YieldOp)
def run_yield(
    self, interpreter: Interpreter, op: riscv_scf.YieldOp, args: tuple[Any, ...]
):
    return ReturnedValues(args), ()

run_while(interpreter: Interpreter, op: riscv_scf.WhileOp, args: tuple[Any, ...])

Source code in xdsl/interpreters/riscv_scf.py
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
@impl(riscv_scf.WhileOp)
def run_while(
    self,
    interpreter: Interpreter,
    op: riscv_scf.WhileOp,
    args: tuple[Any, ...],
):
    cond, *results = interpreter.run_ssacfg_region(
        op.before_region, args, "while_head"
    )

    while cond:
        args = interpreter.run_ssacfg_region(
            op.after_region, tuple(results), "while_body"
        )
        cond, *results = interpreter.run_ssacfg_region(
            op.before_region, args, "while_head"
        )

    return tuple(results)

run_condition(interpreter: Interpreter, op: riscv_scf.ConditionOp, args: tuple[Any, ...])

Source code in xdsl/interpreters/riscv_scf.py
67
68
69
70
71
@impl_terminator(riscv_scf.ConditionOp)
def run_condition(
    self, interpreter: Interpreter, op: riscv_scf.ConditionOp, args: tuple[Any, ...]
):
    return ReturnedValues(args), ()