pmgen progress
authorClifford Wolf <clifford@clifford.at>
Tue, 30 Apr 2019 08:51:51 +0000 (10:51 +0200)
committerClifford Wolf <clifford@clifford.at>
Tue, 30 Apr 2019 08:51:51 +0000 (10:51 +0200)
Signed-off-by: Clifford Wolf <clifford@clifford.at>
passes/pmgen/ice40_dsp.cc
passes/pmgen/peepopt.cc
passes/pmgen/peepopt_shiftmul.pmg
passes/pmgen/pmgen.py

index 36ba1dabeaf6fb99518e4e018c708e69698f8d1c..39d033a04f449e49e863d8ebf98adc23fdfbd728 100644 (file)
 
 #include "kernel/yosys.h"
 #include "kernel/sigtools.h"
-#include "passes/pmgen/ice40_dsp_pm.h"
 
 USING_YOSYS_NAMESPACE
 PRIVATE_NAMESPACE_BEGIN
 
+#include "passes/pmgen/ice40_dsp_pm.h"
+
 void create_ice40_dsp(ice40_dsp_pm &pm)
 {
        auto &st = pm.st_ice40_dsp;
index e9aa8e37aa1cd3294a2877e90bc59b6ac5a56af1..0584878c367187536ca7fb22968a3e8b1a69f27e 100644 (file)
 
 #include "kernel/yosys.h"
 #include "kernel/sigtools.h"
-#include "passes/pmgen/peepopt_pm.h"
 
 USING_YOSYS_NAMESPACE
 PRIVATE_NAMESPACE_BEGIN
 
+bool did_something;
+
+#include "passes/pmgen/peepopt_pm.h"
+
 struct PeepoptPass : public Pass {
        PeepoptPass() : Pass("peepopt", "collection of peephole optimizers") { }
        void help() YS_OVERRIDE
@@ -51,8 +54,12 @@ struct PeepoptPass : public Pass {
                extra_args(args, argidx, design);
 
                for (auto module : design->selected_modules()) {
-                       peepopt_pm pm(module, module->selected_cells());
-                       pm.run_shiftmul();
+                       did_something = true;
+                       while (did_something) {
+                               did_something = false;
+                               peepopt_pm pm(module, module->selected_cells());
+                               pm.run_shiftmul();
+                       }
                }
        }
 } PeepoptPass;
index d9d5757ca7c2d52644da355ee116399bd212aa2c..1f9b3c2b94c594cc313d710250737471e3b54e7f 100644 (file)
@@ -45,6 +45,7 @@ code
        if (GetSize(port(shift, \Y)) > const_factor)
                reject;
 
+       did_something = true;
        log("shiftmul pattern in %s: shift=%s, mul=%s\n", log_id(module), log_id(shift), log_id(mul));
 
        int new_const_factor_log2 = ceil_log2(const_factor);
index 5860c634ae23a4bd7224f7bce70e0d42d04b3f70..95a0a5f5d641d3704dd80d90feeda98bbbb5ee52 100644 (file)
@@ -11,8 +11,9 @@ prefix = None
 pmgfiles = list()
 outfile = None
 debug = False
+genhdr = False
 
-opts, args = getopt.getopt(sys.argv[1:], "p:o:d")
+opts, args = getopt.getopt(sys.argv[1:], "p:o:dg")
 
 for o, a in opts:
     if o == "-p":
@@ -21,6 +22,8 @@ for o, a in opts:
         outfile = a
     elif o == "-d":
         debug = True
+    elif o == "-g":
+        genhdr = True
 
 if outfile is None:
     outfile = "/dev/stdout"
@@ -249,12 +252,12 @@ with open(outfile, "w") as f:
         print("// Generated by pmgen.py from {}".format(fn), file=f)
     print("", file=f)
 
-    print("#include \"kernel/yosys.h\"", file=f)
-    print("#include \"kernel/sigtools.h\"", file=f)
-    print("", file=f)
-
-    print("YOSYS_NAMESPACE_BEGIN", file=f)
-    print("", file=f)
+    if genhdr:
+        print("#include \"kernel/yosys.h\"", file=f)
+        print("#include \"kernel/sigtools.h\"", file=f)
+        print("", file=f)
+        print("YOSYS_NAMESPACE_BEGIN", file=f)
+        print("", file=f)
 
     print("struct {}_pm {{".format(prefix), file=f)
     print("  Module *module;", file=f)
@@ -564,5 +567,7 @@ with open(outfile, "w") as f:
         print("", file=f)
 
     print("};", file=f)
-    print("", file=f)
-    print("YOSYS_NAMESPACE_END", file=f)
+
+    if genhdr:
+        print("", file=f)
+        print("YOSYS_NAMESPACE_END", file=f)