From 4306bebe586dc3a6a954a6630b9f0292c1b1b1dd Mon Sep 17 00:00:00 2001 From: Clifford Wolf Date: Tue, 30 Apr 2019 10:51:51 +0200 Subject: [PATCH] pmgen progress Signed-off-by: Clifford Wolf --- passes/pmgen/ice40_dsp.cc | 3 ++- passes/pmgen/peepopt.cc | 13 ++++++++++--- passes/pmgen/peepopt_shiftmul.pmg | 1 + passes/pmgen/pmgen.py | 23 ++++++++++++++--------- 4 files changed, 27 insertions(+), 13 deletions(-) diff --git a/passes/pmgen/ice40_dsp.cc b/passes/pmgen/ice40_dsp.cc index 36ba1dabe..39d033a04 100644 --- a/passes/pmgen/ice40_dsp.cc +++ b/passes/pmgen/ice40_dsp.cc @@ -19,11 +19,12 @@ #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; diff --git a/passes/pmgen/peepopt.cc b/passes/pmgen/peepopt.cc index e9aa8e37a..0584878c3 100644 --- a/passes/pmgen/peepopt.cc +++ b/passes/pmgen/peepopt.cc @@ -19,11 +19,14 @@ #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; diff --git a/passes/pmgen/peepopt_shiftmul.pmg b/passes/pmgen/peepopt_shiftmul.pmg index d9d5757ca..1f9b3c2b9 100644 --- a/passes/pmgen/peepopt_shiftmul.pmg +++ b/passes/pmgen/peepopt_shiftmul.pmg @@ -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); diff --git a/passes/pmgen/pmgen.py b/passes/pmgen/pmgen.py index 5860c634a..95a0a5f5d 100644 --- a/passes/pmgen/pmgen.py +++ b/passes/pmgen/pmgen.py @@ -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) -- 2.30.2