def remap_clocks(ports, clock_map):
    """
    Remaps clock dependencies of all ports and returns a new port map.
    Does not remap clocks for "P1" and "P2" ports.
    """

    new_ports = {
        "input": set(),
        "clock": set(),
        "output": set(),
    }

    for key in ["input", "clock", "output"]:
        for name, width, assoc_clock in ports[key]:

            # P1 and P2 are not subject to the remap
            if "P1" not in name and "P2" not in name:

                # Remap the associated clock
                if assoc_clock in clock_map:
                    assoc_clock = clock_map[assoc_clock]

            new_ports[key].add((
                name,
                width,
                assoc_clock,
            ))

    return new_ports