Skip to content

Commit 08c5c7e

Browse files
rsetaluriRajsekhar Setaluri
authored andcommitted
Memoize first clock type of defn
1 parent 16abe6b commit 08c5c7e

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

magma/clock.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import functools
12
from .t import Direction, In
23
from .digital import DigitalMeta, Digital
34
from .wire import wire
@@ -126,16 +127,22 @@ def _get_first_clock(port, clocktype):
126127
return None
127128

128129

129-
def wireclocktype(defn, inst, clocktype):
130+
def _get_first_clock_of_defn(defn, clocktype):
130131
# Check common case: top level clock port
131132
clks = (port if isinstance(port, clocktype) else None
132133
for port in defn.interface.ports.values())
133134
defnclk = _first(clks)
134-
if defnclk is None:
135-
# Check recursive types
136-
clks = (_get_first_clock(port, clocktype)
137-
for port in defn.interface.ports.values())
138-
defnclk = _first(clks)
135+
if defnclk is not None:
136+
return defnclk
137+
# Check recursive types
138+
clks = (_get_first_clock(port, clocktype)
139+
for port in defn.interface.ports.values())
140+
return _first(clks)
141+
142+
143+
@functools.lru_cache(maxsize=None)
144+
def wireclocktype(defn, inst, clocktype):
145+
defnclk = _get_first_clock_of_defn(defn, clocktype)
139146
if defnclk is None:
140147
return
141148
for port in inst.interface.inputs(include_clocks=True):

0 commit comments

Comments
 (0)