return module;
}
+void RTLIL::Design::scratchpad_unset(std::string varname)
+{
+ scratchpad.erase(varname);
+}
+
+void RTLIL::Design::scratchpad_set_int(std::string varname, int value)
+{
+ scratchpad[varname] = stringf("%d", value);
+}
+
+void RTLIL::Design::scratchpad_set_bool(std::string varname, bool value)
+{
+ scratchpad[varname] = value ? "true" : "false";
+}
+
+void RTLIL::Design::scratchpad_set_string(std::string varname, std::string value)
+{
+ scratchpad[varname] = value;
+}
+
+int RTLIL::Design::scratchpad_get_int(std::string varname, int default_value) const
+{
+ if (scratchpad.count(varname) == 0)
+ return default_value;
+
+ std::string str = scratchpad.at(varname);
+
+ if (str == "0" || str == "false")
+ return 0;
+
+ if (str == "1" || str == "true")
+ return 1;
+
+ char *endptr = nullptr;
+ long int parsed_value = strtol(str.c_str(), &endptr, 10);
+ return *endptr ? default_value : parsed_value;
+}
+
+bool RTLIL::Design::scratchpad_get_bool(std::string varname, bool default_value) const
+{
+ if (scratchpad.count(varname) == 0)
+ return default_value;
+
+ std::string str = scratchpad.at(varname);
+
+ if (str == "0" || str == "false")
+ return false;
+
+ if (str == "1" || str == "true")
+ return true;
+
+ return default_value;
+}
+
+std::string RTLIL::Design::scratchpad_get_string(std::string varname, std::string default_value) const
+{
+ if (scratchpad.count(varname) == 0)
+ return default_value;
+ return scratchpad.at(varname);
+}
+
void RTLIL::Design::remove(RTLIL::Module *module)
{
for (auto mon : monitors)
struct RTLIL::Design
{
std::set<RTLIL::Monitor*> monitors;
+ std::map<std::string, std::string> scratchpad;
int refcount_modules_;
std::map<RTLIL::IdString, RTLIL::Module*> modules_;
RTLIL::Module *addModule(RTLIL::IdString name);
void remove(RTLIL::Module *module);
+ void scratchpad_unset(std::string varname);
+
+ void scratchpad_set_int(std::string varname, int value);
+ void scratchpad_set_bool(std::string varname, bool value);
+ void scratchpad_set_string(std::string varname, std::string value);
+
+ int scratchpad_get_int(std::string varname, int default_value = 0) const;
+ bool scratchpad_get_bool(std::string varname, bool default_value = false) const;
+ std::string scratchpad_get_string(std::string varname, std::string default_value = std::string()) const;
+
void check();
void optimize();
*
*/
-#include "opt_status.h"
#include "kernel/register.h"
#include "kernel/log.h"
#include <stdlib.h>
#include <stdio.h>
-bool OPT_DID_SOMETHING;
-
struct OptPass : public Pass {
OptPass() : Pass("opt", "perform simple optimizations") { }
virtual void help()
while (1) {
Pass::call(design, "opt_const" + opt_const_args);
Pass::call(design, "opt_share");
- OPT_DID_SOMETHING = false;
+ design->scratchpad_unset("opt.did_something");
Pass::call(design, "opt_rmdff");
- if (OPT_DID_SOMETHING == false)
+ if (design->scratchpad_get_bool("opt.did_something") == false)
break;
Pass::call(design, "opt_clean" + opt_clean_args);
log_header("Rerunning OPT passes. (Removed registers in this run.)\n");
Pass::call(design, "opt_const" + opt_const_args);
Pass::call(design, "opt_share -nomux");
while (1) {
- OPT_DID_SOMETHING = false;
+ design->scratchpad_unset("opt.did_something");
Pass::call(design, "opt_muxtree");
Pass::call(design, "opt_reduce" + opt_reduce_args);
Pass::call(design, "opt_share");
Pass::call(design, "opt_rmdff");
Pass::call(design, "opt_clean" + opt_clean_args);
Pass::call(design, "opt_const" + opt_const_args);
- if (OPT_DID_SOMETHING == false)
+ if (design->scratchpad_get_bool("opt.did_something") == false)
break;
log_header("Rerunning OPT passes. (Maybe there is more to do..)\n");
}
*
*/
-#include "opt_status.h"
#include "kernel/register.h"
#include "kernel/sigtools.h"
#include "kernel/log.h"
for (auto cell : unused) {
if (verbose)
log(" removing unused `%s' cell `%s'.\n", cell->type.c_str(), cell->name.c_str());
- OPT_DID_SOMETHING = true;
+ module->design->scratchpad_set_bool("opt.did_something", true);
module->remove(cell);
count_rm_cells++;
}
for (auto &mod_it : design->modules_) {
if (design->selected_whole_module(mod_it.first) && mod_it.second->processes.size() == 0)
do {
- OPT_DID_SOMETHING = false;
+ design->scratchpad_unset("opt.did_something");
rmunused_module(mod_it.second, purge_mode, false);
- } while (OPT_DID_SOMETHING);
+ } while (design->scratchpad_get_bool("opt.did_something"));
}
if (count_rm_cells > 0 || count_rm_wires > 0)
*
*/
-#include "opt_status.h"
#include "kernel/register.h"
#include "kernel/sigtools.h"
#include "kernel/celltypes.h"
log("Setting undriven signal in %s to undef: %s\n", RTLIL::id2cstr(module->name), log_signal(c));
module->connect(RTLIL::SigSig(c, RTLIL::SigSpec(RTLIL::State::Sx, c.width)));
- OPT_DID_SOMETHING = true;
+ did_something = true;
}
}
assign_map.add(Y, out_val);
module->connect(Y, out_val);
module->remove(cell);
- OPT_DID_SOMETHING = true;
did_something = true;
}
cover_list("opt.opt_const.fine.group", "$not", "$pos", "$bu0", "$and", "$or", "$xor", "$xnor", cell->type.str());
module->remove(cell);
- OPT_DID_SOMETHING = true;
did_something = true;
return true;
}
cell->type.c_str(), cell->name.c_str(), module->name.c_str(), log_signal(sig_a), log_signal(new_a));
cell->setPort("\\A", sig_a = new_a);
cell->parameters.at("\\A_WIDTH") = 1;
- OPT_DID_SOMETHING = true;
did_something = true;
}
}
cell->type.c_str(), cell->name.c_str(), module->name.c_str(), log_signal(sig_a), log_signal(new_a));
cell->setPort("\\A", sig_a = new_a);
cell->parameters.at("\\A_WIDTH") = 1;
- OPT_DID_SOMETHING = true;
did_something = true;
}
}
cell->type.c_str(), cell->name.c_str(), module->name.c_str(), log_signal(sig_b), log_signal(new_b));
cell->setPort("\\B", sig_b = new_b);
cell->parameters.at("\\B_WIDTH") = 1;
- OPT_DID_SOMETHING = true;
did_something = true;
}
}
cell->setPort("\\A", cell->getPort("\\B"));
cell->setPort("\\B", tmp);
cell->setPort("\\S", invert_map.at(assign_map(cell->getPort("\\S"))));
- OPT_DID_SOMETHING = true;
did_something = true;
goto next_cell;
}
cell->parameters.erase("\\B_WIDTH");
cell->parameters.erase("\\B_SIGNED");
cell->unsetPort("\\B");
- OPT_DID_SOMETHING = true;
did_something = true;
}
goto next_cell;
module->connect(cell->getPort("\\Y"), sig_y);
module->remove(cell);
- OPT_DID_SOMETHING = true;
did_something = true;
goto next_cell;
}
cell->parameters.erase("\\B_SIGNED");
cell->check();
- OPT_DID_SOMETHING = true;
did_something = true;
goto next_cell;
}
cell->type = "$not";
} else
cell->type = "$_NOT_";
- OPT_DID_SOMETHING = true;
did_something = true;
goto next_cell;
}
cell->type = "$and";
} else
cell->type = "$_AND_";
- OPT_DID_SOMETHING = true;
did_something = true;
goto next_cell;
}
cell->type = "$or";
} else
cell->type = "$_OR_";
- OPT_DID_SOMETHING = true;
did_something = true;
goto next_cell;
}
cell->type = "$mux";
cell->parameters.erase("\\S_WIDTH");
}
- OPT_DID_SOMETHING = true;
did_something = true;
}
}
module->connect(RTLIL::SigSig(sig_y, RTLIL::SigSpec(0, sig_y.size())));
module->remove(cell);
- OPT_DID_SOMETHING = true;
did_something = true;
goto next_cell;
}
cell->setPort("\\B", new_b);
cell->check();
- OPT_DID_SOMETHING = true;
did_something = true;
goto next_cell;
}
do {
did_something = false;
replace_const_cells(design, module, false, mux_undef, mux_bool, do_fine, keepdc);
+ if (did_something)
+ design->scratchpad_set_bool("opt.did_something", true);
} while (did_something);
replace_const_cells(design, module, true, mux_undef, mux_bool, do_fine, keepdc);
} while (did_something);
*
*/
-#include "opt_status.h"
#include "kernel/register.h"
#include "kernel/sigtools.h"
#include "kernel/log.h"
} else {
log(" dead port %zd/%zd on %s %s.\n", port_idx+1, mi.ports.size(),
mi.cell->type.c_str(), mi.cell->name.c_str());
- OPT_DID_SOMETHING = true;
removed_count++;
}
}
total_count += worker.removed_count;
}
}
+ if (total_count)
+ design->scratchpad_set_bool("opt.did_something", true);
log("Removed %d multiplexer ports.\n", total_count);
}
} OptMuxtreePass;
*
*/
-#include "opt_status.h"
#include "kernel/register.h"
#include "kernel/sigtools.h"
#include "kernel/log.h"
if (new_sig_a != sig_a || sig_a.size() != cell->getPort("\\A").size()) {
log(" New input vector for %s cell %s: %s\n", cell->type.c_str(), cell->name.c_str(), log_signal(new_sig_a));
did_something = true;
- OPT_DID_SOMETHING = true;
total_count++;
}
if (new_sig_s.size() != sig_s.size()) {
log(" New ctrl vector for %s cell %s: %s\n", cell->type.c_str(), cell->name.c_str(), log_signal(new_sig_s));
did_something = true;
- OPT_DID_SOMETHING = true;
total_count++;
}
module->check();
did_something = true;
- OPT_DID_SOMETHING = true;
total_count++;
}
}
} while (1);
}
+ if (total_count)
+ design->scratchpad_set_bool("opt.did_something", true);
log("Performed a total of %d changes.\n", total_count);
}
} OptReducePass;
*
*/
-#include "opt_status.h"
#include "kernel/register.h"
#include "kernel/sigtools.h"
#include "kernel/log.h"
delete_dff:
log("Removing %s (%s) from module %s.\n", dff->name.c_str(), dff->type.c_str(), mod->name.c_str());
- OPT_DID_SOMETHING = true;
mod->remove(dff);
return true;
}
assign_map.clear();
mux_drivers.clear();
+
+ if (total_count)
+ design->scratchpad_set_bool("opt.did_something", true);
log("Replaced %d DFF cells.\n", total_count);
}
} OptRmdffPass;
*
*/
-#include "opt_status.h"
#include "kernel/register.h"
#include "kernel/sigtools.h"
#include "kernel/log.h"
}
log(" Removing %s cell `%s' from module `%s'.\n", cell->type.c_str(), cell->name.c_str(), module->name.c_str());
module->remove(cell);
- OPT_DID_SOMETHING = true;
total_count++;
} else {
sharemap[cell] = cell;
total_count += worker.total_count;
}
+ if (total_count)
+ design->scratchpad_set_bool("opt.did_something", true);
log("Removed a total of %d cells.\n", total_count);
}
} OptSharePass;
+++ /dev/null
-/*
- * yosys -- Yosys Open SYnthesis Suite
- *
- * Copyright (C) 2012 Clifford Wolf <clifford@clifford.at>
- *
- * 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.
- *
- */
-
-#ifndef OPT_STATUS_H
-#define OPT_STATUS_H
-
-extern bool OPT_DID_SOMETHING;
-
-#endif
-