Skip to content

Pass metrics

pass_metrics

count_number_of_operations(module: ModuleOp) -> dict[str, int]

This function takes a ModuleOp and returns a dictionary containing the number of occurences of each Operation in the ModuleOp.

Source code in xdsl/interactive/pass_metrics.py
 6
 7
 8
 9
10
11
def count_number_of_operations(module: ModuleOp) -> dict[str, int]:
    """
    This function takes a ModuleOp and returns a dictionary containing the number of
    occurences of each Operation in the ModuleOp.
    """
    return Counter(op.name for op in module.walk())

get_diff_operation_count(input_operation_count_tuple: tuple[tuple[str, int], ...], output_operation_count_tuple: tuple[tuple[str, int], ...]) -> tuple[tuple[str, int, str], ...]

Function returning a tuple of tuples containing the diff of the input and output operation name and count.

Source code in xdsl/interactive/pass_metrics.py
14
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
41
42
def get_diff_operation_count(
    input_operation_count_tuple: tuple[tuple[str, int], ...],
    output_operation_count_tuple: tuple[tuple[str, int], ...],
) -> tuple[tuple[str, int, str], ...]:
    """
    Function returning a tuple of tuples containing the diff of the input and output
    operation name and count.
    """
    input_op_count_dict = dict(input_operation_count_tuple)
    output_op_count_dict = dict(output_operation_count_tuple)
    all_keys = {*input_op_count_dict, *output_op_count_dict}

    res: dict[str, tuple[int, str]] = {}
    for k in all_keys:
        input_count = input_op_count_dict.get(k, 0)
        output_count = output_op_count_dict.get(k, 0)
        diff = output_count - input_count

        # convert diff to string
        if diff == 0:
            diff_str = "="
        elif diff > 0:
            diff_str = f"+{diff}"
        else:
            diff_str = str(diff)

        res[k] = (output_count, diff_str)

    return tuple((k, v0, v1) for (k, (v0, v1)) in sorted(res.items()))