import collections


def calculate_pred(func):
    """Return a dictionary with predecessors for each basic block."""
    pred = collections.defaultdict(list)
    for basic_block in func.basic_blocks:
        for successor in basic_block.get_successors():
            if basic_block not in pred[successor]:
                pred[successor].append(basic_block)
    return pred