/* * yosys -- Yosys Open SYnthesis Suite * * Copyright (C) 2024 Silimate Inc. * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * */ #include "kernel/yosys.h" #include "kernel/sigtools.h" #include "kernel/ff.h" #include USING_YOSYS_NAMESPACE PRIVATE_NAMESPACE_BEGIN void dump_flipflops_to_file(RTLIL::Design *design, const std::string &filename) { std::ofstream outfile(filename); if (!outfile.is_open()) { log_error("Cannot open file %s for writing\n", filename.c_str()); return; } for (auto module : design->selected_modules()) { outfile << "Module: " << log_id(module) << "\n"; log("Module: %s\n", log_id(module)); for (auto cell : module->cells()) { if (cell->is_builtin_ff()) { outfile << " FF: " << log_id(cell) << " (type: " << log_id(cell->type) << ")\n"; log(" FF: %s (type: %s)\n", log_id(cell), log_id(cell->type)); } } outfile << "\n"; } outfile.close(); log("Wrote flip-flop list to %s\n", filename.c_str()); } struct SatClockgatePass : public Pass { SatClockgatePass() : Pass("sat_clockgate", "SAT-based inferred clock gating") { } void help() override { log("\n"); log(" sat_clockgate [options] [selection]\n"); log("\n"); log("This command performs SAT-based inferred clock gating insertion.\n"); log("\n"); log(" -threshold \n"); log(" minimum number of clock cycles that must match for clock gating\n"); log(" to be inserted (default: 1)\n"); log("\n"); } void execute(std::vector args, RTLIL::Design *design) override { log_header(design, "Executing SAT_CLOCKGATE pass.\n"); int threshold = 1; size_t argidx; for (argidx = 1; argidx < args.size(); argidx++) { if (args[argidx] == "-threshold" && argidx+1 < args.size()) { threshold = std::stoi(args[++argidx]); continue; } break; } extra_args(args, argidx, design); log("Using threshold: %d\n", threshold); // Dump all flip-flops to file dump_flipflops_to_file(design, "flip_flops.txt"); for (auto module : design->selected_modules()) { log("Processing module %s...\n", log_id(module)); // TODO: Implement SAT-based clock gating logic // Example: calling SAT pass // Pass::call(design, stringf("sat -verify -prove 1 %s", log_id(module))); } } } SatClockgatePass; PRIVATE_NAMESPACE_END