From 75f9e9cb452013c8a07333d486a59c238e1b446f Mon Sep 17 00:00:00 2001 From: whitequark Date: Mon, 7 Dec 2020 08:42:45 +0000 Subject: bugpoint: add -command option. --- passes/cmds/bugpoint.cc | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/passes/cmds/bugpoint.cc b/passes/cmds/bugpoint.cc index 81d7a34bb..d32d33560 100644 --- a/passes/cmds/bugpoint.cc +++ b/passes/cmds/bugpoint.cc @@ -30,7 +30,7 @@ struct BugpointPass : public Pass { { // |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---| log("\n"); - log(" bugpoint [options] -script \n"); + log(" bugpoint [options] [-script | -command \"\"]\n"); log("\n"); log("This command minimizes the current design that is known to crash Yosys with the\n"); log("given script into a smaller testcase. It does this by removing an arbitrary part\n"); @@ -39,8 +39,8 @@ struct BugpointPass : public Pass { log("still causes a crash. Once this command finishes, it replaces the current design\n"); log("with the smallest testcase it was able to produce.\n"); log("\n"); - log(" -script \n"); - log(" use this script to crash Yosys. required.\n"); + log(" -script | -command \"\"\n"); + log(" use this script file or command to crash Yosys. required.\n"); log("\n"); log(" -yosys \n"); log(" use this Yosys binary. if not specified, `yosys` is used.\n"); @@ -85,7 +85,7 @@ struct BugpointPass : public Pass { log("\n"); } - bool run_yosys(RTLIL::Design *design, string yosys_cmd, string script) + bool run_yosys(RTLIL::Design *design, string yosys_cmd, string yosys_arg) { design->sort(); @@ -93,7 +93,7 @@ struct BugpointPass : public Pass { RTLIL_BACKEND::dump_design(f, design, /*only_selected=*/false, /*flag_m=*/true, /*flag_n=*/false); f.close(); - string yosys_cmdline = stringf("%s -qq -L bugpoint-case.log -s %s bugpoint-case.il", yosys_cmd.c_str(), script.c_str()); + string yosys_cmdline = stringf("%s -qq -L bugpoint-case.log %s bugpoint-case.il", yosys_cmd.c_str(), yosys_arg.c_str()); return run_command(yosys_cmdline) == 0; } @@ -315,7 +315,7 @@ struct BugpointPass : public Pass { void execute(std::vector args, RTLIL::Design *design) override { - string yosys_cmd = "yosys", script, grep; + string yosys_cmd = "yosys", yosys_arg, grep; bool fast = false, clean = false; bool modules = false, ports = false, cells = false, connections = false, assigns = false, updates = false, has_part = false; @@ -330,7 +330,15 @@ struct BugpointPass : public Pass { continue; } if (args[argidx] == "-script" && argidx + 1 < args.size()) { - script = args[++argidx]; + if (!yosys_arg.empty()) + log_cmd_error("A -script or -command option can be only provided once!\n"); + yosys_arg = stringf("-s %s", args[++argidx].c_str()); + continue; + } + if (args[argidx] == "-command" && argidx + 1 < args.size()) { + if (!yosys_arg.empty()) + log_cmd_error("A -script or -command option can be only provided once!\n"); + yosys_arg = stringf("-p %s", args[++argidx].c_str()); continue; } if (args[argidx] == "-grep" && argidx + 1 < args.size()) { @@ -379,8 +387,8 @@ struct BugpointPass : public Pass { } extra_args(args, argidx, design); - if (script.empty()) - log_cmd_error("Missing -script option.\n"); + if (yosys_arg.empty()) + log_cmd_error("Missing -script or -command option.\n"); if (!has_part) { @@ -396,8 +404,8 @@ struct BugpointPass : public Pass { log_cmd_error("This command only operates on fully selected designs!\n"); RTLIL::Design *crashing_design = clean_design(design, clean); - if (run_yosys(crashing_design, yosys_cmd, script)) - log_cmd_error("The provided script file and Yosys binary do not crash on this design!\n"); + if (run_yosys(crashing_design, yosys_cmd, yosys_arg)) + log_cmd_error("The provided script file or command and Yosys binary do not crash on this design!\n"); if (!check_logfile(grep)) log_cmd_error("The provided grep string is not found in the log file!\n"); @@ -413,12 +421,12 @@ struct BugpointPass : public Pass { if (clean) { RTLIL::Design *testcase = clean_design(simplified); - crashes = !run_yosys(testcase, yosys_cmd, script); + crashes = !run_yosys(testcase, yosys_cmd, yosys_arg); delete testcase; } else { - crashes = !run_yosys(simplified, yosys_cmd, script); + crashes = !run_yosys(simplified, yosys_cmd, yosys_arg); } if (crashes && check_logfile(grep)) -- cgit v1.2.3 From b1135a88dd24b294c41f8964cfc425d938e3dbee Mon Sep 17 00:00:00 2001 From: whitequark Date: Mon, 7 Dec 2020 08:23:32 +0000 Subject: bugpoint: accept quoted strings in -grep. --- passes/cmds/bugpoint.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/passes/cmds/bugpoint.cc b/passes/cmds/bugpoint.cc index d32d33560..8197b21f7 100644 --- a/passes/cmds/bugpoint.cc +++ b/passes/cmds/bugpoint.cc @@ -45,7 +45,7 @@ struct BugpointPass : public Pass { log(" -yosys \n"); log(" use this Yosys binary. if not specified, `yosys` is used.\n"); log("\n"); - log(" -grep \n"); + log(" -grep \"\"\n"); log(" only consider crashes that place this string in the log file.\n"); log("\n"); log(" -fast\n"); @@ -102,6 +102,9 @@ struct BugpointPass : public Pass { if (grep.empty()) return true; + if (grep.size() > 2 && grep.front() == '"' && grep.back() == '"') + grep = grep.substr(1, grep.size() - 2); + std::ifstream f("bugpoint-case.log"); while (!f.eof()) { -- cgit v1.2.3 From 2b474a01e11342d7ed3e8d67b0c4561fa8628429 Mon Sep 17 00:00:00 2001 From: whitequark Date: Mon, 7 Dec 2020 08:27:25 +0000 Subject: bugpoint: try to remove whole processes first. --- passes/cmds/bugpoint.cc | 44 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/passes/cmds/bugpoint.cc b/passes/cmds/bugpoint.cc index 8197b21f7..f2d70a3d1 100644 --- a/passes/cmds/bugpoint.cc +++ b/passes/cmds/bugpoint.cc @@ -77,6 +77,10 @@ struct BugpointPass : public Pass { log(" -connections\n"); log(" try to reconnect ports to 'x.\n"); log("\n"); + log(" -processes\n"); + log(" try to remove processes. processes with a (* bugpoint_keep *) attribute\n"); + log(" will be skipped.\n"); + log("\n"); log(" -assigns\n"); log(" try to remove process assigns from cases.\n"); log("\n"); @@ -132,7 +136,7 @@ struct BugpointPass : public Pass { return design_copy; } - RTLIL::Design *simplify_something(RTLIL::Design *design, int &seed, bool stage2, bool modules, bool ports, bool cells, bool connections, bool assigns, bool updates) + RTLIL::Design *simplify_something(RTLIL::Design *design, int &seed, bool stage2, bool modules, bool ports, bool cells, bool connections, bool processes, bool assigns, bool updates) { RTLIL::Design *design_copy = new RTLIL::Design; for (auto module : design->modules()) @@ -197,7 +201,6 @@ struct BugpointPass : public Pass { if (mod->get_blackbox_attribute()) continue; - Cell *removed_cell = nullptr; for (auto cell : mod->cells()) { @@ -260,6 +263,33 @@ struct BugpointPass : public Pass { } } } + if (processes) + { + for (auto mod : design_copy->modules()) + { + if (mod->get_blackbox_attribute()) + continue; + + RTLIL::IdString removed_process; + for (auto process : mod->processes) + { + if (process.second->get_bool_attribute(ID::bugpoint_keep)) + continue; + + if (index++ == seed) + { + log_header(design, "Trying to remove process %s.%s.\n", log_id(mod), log_id(process.first)); + removed_process = process.first; + break; + } + } + if (!removed_process.empty()) { + delete mod->processes[removed_process]; + mod->processes.erase(removed_process); + return design_copy; + } + } + } if (assigns) { for (auto mod : design_copy->modules()) @@ -320,7 +350,7 @@ struct BugpointPass : public Pass { { string yosys_cmd = "yosys", yosys_arg, grep; bool fast = false, clean = false; - bool modules = false, ports = false, cells = false, connections = false, assigns = false, updates = false, has_part = false; + bool modules = false, ports = false, cells = false, connections = false, processes = false, assigns = false, updates = false, has_part = false; log_header(design, "Executing BUGPOINT pass (minimize testcases).\n"); log_push(); @@ -376,6 +406,11 @@ struct BugpointPass : public Pass { has_part = true; continue; } + if (args[argidx] == "-processes") { + processes = true; + has_part = true; + continue; + } if (args[argidx] == "-assigns") { assigns = true; has_part = true; @@ -399,6 +434,7 @@ struct BugpointPass : public Pass { ports = true; cells = true; connections = true; + processes = true; assigns = true; updates = true; } @@ -416,7 +452,7 @@ struct BugpointPass : public Pass { bool found_something = false, stage2 = false; while (true) { - if (RTLIL::Design *simplified = simplify_something(crashing_design, seed, stage2, modules, ports, cells, connections, assigns, updates)) + if (RTLIL::Design *simplified = simplify_something(crashing_design, seed, stage2, modules, ports, cells, connections, processes, assigns, updates)) { simplified = clean_design(simplified, fast, /*do_delete=*/true); -- cgit v1.2.3 From 1838edf35cbd558d3a9a9c4a1ea10e080e8d56ab Mon Sep 17 00:00:00 2001 From: whitequark Date: Mon, 7 Dec 2020 09:24:35 +0000 Subject: bugpoint: add -wires option. --- kernel/rtlil.cc | 2 +- passes/cmds/bugpoint.cc | 41 ++++++++++++++++++++++++++++++++++++++--- 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/kernel/rtlil.cc b/kernel/rtlil.cc index a9f585616..1faf376e7 100644 --- a/kernel/rtlil.cc +++ b/kernel/rtlil.cc @@ -1826,7 +1826,7 @@ void RTLIL::Module::remove(const pool &wires) sig.pack(); for (auto &c : sig.chunks_) if (c.wire != NULL && wires_p->count(c.wire)) { - c.wire = module->addWire(NEW_ID, c.width); + c.wire = module->addWire(stringf("$delete_wire$%d", autoidx++), c.width); c.offset = 0; } } diff --git a/passes/cmds/bugpoint.cc b/passes/cmds/bugpoint.cc index f2d70a3d1..da81e7f09 100644 --- a/passes/cmds/bugpoint.cc +++ b/passes/cmds/bugpoint.cc @@ -136,7 +136,7 @@ struct BugpointPass : public Pass { return design_copy; } - RTLIL::Design *simplify_something(RTLIL::Design *design, int &seed, bool stage2, bool modules, bool ports, bool cells, bool connections, bool processes, bool assigns, bool updates) + RTLIL::Design *simplify_something(RTLIL::Design *design, int &seed, bool stage2, bool modules, bool ports, bool cells, bool connections, bool processes, bool assigns, bool updates, bool wires) { RTLIL::Design *design_copy = new RTLIL::Design; for (auto module : design->modules()) @@ -343,6 +343,35 @@ struct BugpointPass : public Pass { } } } + if (wires) + { + for (auto mod : design_copy->modules()) + { + if (mod->get_blackbox_attribute()) + continue; + + Wire *removed_wire = nullptr; + for (auto wire : mod->wires()) + { + if (wire->get_bool_attribute(ID::bugpoint_keep)) + continue; + + if (wire->name.begins_with("$delete_wire")) + continue; + + if (index++ == seed) + { + log_header(design, "Trying to remove wire %s.%s.\n", log_id(mod), log_id(wire)); + removed_wire = wire; + break; + } + } + if (removed_wire) { + mod->remove({removed_wire}); + return design_copy; + } + } + } return nullptr; } @@ -350,7 +379,7 @@ struct BugpointPass : public Pass { { string yosys_cmd = "yosys", yosys_arg, grep; bool fast = false, clean = false; - bool modules = false, ports = false, cells = false, connections = false, processes = false, assigns = false, updates = false, has_part = false; + bool modules = false, ports = false, cells = false, connections = false, processes = false, assigns = false, updates = false, wires = false, has_part = false; log_header(design, "Executing BUGPOINT pass (minimize testcases).\n"); log_push(); @@ -421,6 +450,11 @@ struct BugpointPass : public Pass { has_part = true; continue; } + if (args[argidx] == "-wires") { + wires = true; + has_part = true; + continue; + } break; } extra_args(args, argidx, design); @@ -437,6 +471,7 @@ struct BugpointPass : public Pass { processes = true; assigns = true; updates = true; + wires = true; } if (!design->full_selection()) @@ -452,7 +487,7 @@ struct BugpointPass : public Pass { bool found_something = false, stage2 = false; while (true) { - if (RTLIL::Design *simplified = simplify_something(crashing_design, seed, stage2, modules, ports, cells, connections, processes, assigns, updates)) + if (RTLIL::Design *simplified = simplify_something(crashing_design, seed, stage2, modules, ports, cells, connections, processes, assigns, updates, wires)) { simplified = clean_design(simplified, fast, /*do_delete=*/true); -- cgit v1.2.3