[libre-riscv-dev] possible reason for nmigen being slow

Luke Kenneth Casson Leighton lkcl at lkcl.net
Thu Aug 8 10:52:25 BST 2019


---
crowd-funded eco-conscious hardware: https://www.crowdsupply.com/eoma68

On Thu, Aug 8, 2019 at 9:49 AM Jacob Lifshay <programmerjake at gmail.com> wrote:
>
> see https://github.com/m-labs/nmigen/issues/170

this is bad practice.  moving those imports to the end "fixed" the
recursive imports

$ grep -r "import" | grep nmigen
nmigen/hdl/ir.py:        from .xfrm import DomainRenamer
nmigen/hdl/ir.py:        from .xfrm import ResetInserter
nmigen/hdl/ir.py:        from .xfrm import DomainLowerer
nmigen/hdl/ir.py:        from .xfrm import SampleLowerer

diff --git a/nmigen/hdl/ir.py b/nmigen/hdl/ir.py
index 773bb8e..f1159ef 100644
--- a/nmigen/hdl/ir.py
+++ b/nmigen/hdl/ir.py
@@ -9,7 +9,6 @@ from ..tools import *
 from .ast import *
 from .cd import *

-
 __all__ = ["UnusedElaboratable", "Elaboratable", "DriverConflict",
"Fragment", "Instance"]


@@ -48,7 +47,6 @@ sys.excepthook = _silence_elaboratable
 class DriverConflict(UserWarning):
     pass

-
 class Fragment:
     @staticmethod
     def get(obj, platform):
@@ -283,7 +281,6 @@ class Fragment:
                 set(memory_subfrags.keys()))

     def _propagate_domains_up(self, hierarchy=("top",)):
-        from .xfrm import DomainRenamer

         domain_subfrags = defaultdict(lambda: set())

@@ -354,13 +351,11 @@ class Fragment:
         return new_domains

     def _insert_domain_resets(self):
-        from .xfrm import ResetInserter

         resets = {cd.name: cd.rst for cd in self.domains.values() if
cd.rst is not None}
         return ResetInserter(resets)(self)

     def _lower_domain_signals(self):
-        from .xfrm import DomainLowerer

         return DomainLowerer(self.domains)(self)

@@ -505,7 +500,6 @@ class Fragment:
                 self.add_ports(sig, dir="i")

     def prepare(self, ports=None, ensure_sync_exists=True):
-        from .xfrm import SampleLowerer

         fragment = SampleLowerer()(self)
         new_domains = fragment._propagate_domains(ensure_sync_exists)
@@ -559,3 +553,9 @@ class Instance(Fragment):
                 raise NameError("Instance keyword argument {}={!r}
does not start with one of "
                                 "\"p_\", \"i_\", \"o_\", or \"io_\""
                                 .format(kw, arg))
+from .xfrm import DomainRenamer
+from .xfrm import ResetInserter
+from .xfrm import DomainLowerer
+from .xfrm import SampleLowerer


completion time reduced by 40% by this simple patch:

diff --git a/nmigen/tracer.py b/nmigen/tracer.py
index eb8a71e..6529610 100644
--- a/nmigen/tracer.py
+++ b/nmigen/tracer.py
@@ -57,5 +57,6 @@ def get_src_loc(src_loc_at=0):
     # n-2th frame: caller of caller (usually user code)
     # Python returns the stack frames reversed, so it is enough to
set limit and grab the very
     # first one in the array.
+    return ("dummy", 1)
     tb = traceback.extract_stack(limit=3 + src_loc_at)
     return (tb[0].filename, tb[0].lineno)



More information about the libre-riscv-dev mailing list