Skip to content

Commit

Permalink
Memoize first clock type of defn
Browse files Browse the repository at this point in the history
  • Loading branch information
rsetaluri authored and Rajsekhar Setaluri committed Apr 15, 2020
1 parent 28a3cc1 commit a06f97f
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions magma/clock.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import functools
from .t import Direction, In
from .digital import DigitalMeta, Digital
from .wire import wire
Expand Down Expand Up @@ -126,16 +127,22 @@ def _get_first_clock(port, clocktype):
return None


def wireclocktype(defn, inst, clocktype):
def _get_first_clock_of_defn(defn, clocktype):
# Check common case: top level clock port
clks = (port if isinstance(port, clocktype) else None
for port in defn.interface.ports.values())
defnclk = _first(clks)
if defnclk is None:
# Check recursive types
clks = (_get_first_clock(port, clocktype)
for port in defn.interface.ports.values())
defnclk = _first(clks)
if defnclk is not None:
return defnclk
# Check recursive types
clks = (_get_first_clock(port, clocktype)
for port in defn.interface.ports.values())
return _first(clks)


@functools.lru_cache(maxsize=None)
def wireclocktype(defn, inst, clocktype):
defnclk = _get_first_clock_of_defn(defn, clocktype)
if defnclk is None:
return
for port in inst.interface.inputs(include_clocks=True):
Expand Down

0 comments on commit a06f97f

Please sign in to comment.