def get_parent_pb(xml_pbtype):
    """
    Returns a parent pb_type of the given one or none if it is a top-level
    complex block
    """
    assert xml_pbtype.tag in ["pb_type", "mode", "interconnect"], xml_pbtype.tag

    # Get immediate parent
    xml_parent = xml_pbtype.getparent()

    # We've hit the end
    if xml_parent is None or xml_parent.tag == "complexblocklist":
        return None

    # The immediate parent is a mode, jump one more level up
    if xml_parent is not None and xml_parent.tag == "mode":
        xml_parent = xml_parent.getparent()

    return xml_parent