3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2025-06-14 09:56:16 +00:00

references - breaking

This commit is contained in:
Emil J. Tywoniak 2024-06-12 19:12:01 +02:00
parent 1c2fb078eb
commit 919e2103c9
5 changed files with 92 additions and 46 deletions

View file

@ -210,9 +210,6 @@ CXX = clang++
CXXFLAGS += -std=$(CXXSTD) -Os CXXFLAGS += -std=$(CXXSTD) -Os
ABCMKARGS += ARCHFLAGS="-DABC_USE_STDINT_H $(ABC_ARCHFLAGS)" ABCMKARGS += ARCHFLAGS="-DABC_USE_STDINT_H $(ABC_ARCHFLAGS)"
CXXFLAGS += -g -fno-omit-frame-pointer -fno-optimize-sibling-calls
LINKFLAGS += -g
ifneq ($(SANITIZER),) ifneq ($(SANITIZER),)
$(info [Clang Sanitizer] $(SANITIZER)) $(info [Clang Sanitizer] $(SANITIZER))
CXXFLAGS += -g -O1 -fno-omit-frame-pointer -fno-optimize-sibling-calls -fsanitize=$(SANITIZER) CXXFLAGS += -g -O1 -fno-omit-frame-pointer -fno-optimize-sibling-calls -fsanitize=$(SANITIZER)
@ -230,6 +227,15 @@ LINKFLAGS += -flto
endif endif
endif endif
ifneq ($(PROFILER),)
$(info [Profiler] $(PROFILER))
CXXFLAGS += -g -fno-omit-frame-pointer -fno-optimize-sibling-calls
LINKFLAGS += -g
ifneq ($(findstring tracy,$(PROFILER)),)
CXXFLAGS += -DTRACY_ENABLE
endif
endif
else ifeq ($(CONFIG),gcc) else ifeq ($(CONFIG),gcc)
CXX = g++ CXX = g++
CXXFLAGS += -std=$(CXXSTD) -Os CXXFLAGS += -std=$(CXXSTD) -Os
@ -598,8 +604,8 @@ $(eval $(call add_include_file,frontends/ast/ast_binding.h))
$(eval $(call add_include_file,frontends/blif/blifparse.h)) $(eval $(call add_include_file,frontends/blif/blifparse.h))
$(eval $(call add_include_file,backends/rtlil/rtlil_backend.h)) $(eval $(call add_include_file,backends/rtlil/rtlil_backend.h))
# See -DTRACY_ENABLE
OBJS += tracy/public/TracyClient.o OBJS += tracy/public/TracyClient.o
CXXFLAGS += -DTRACY_ENABLE
OBJS += kernel/driver.o kernel/register.o kernel/rtlil.o kernel/log.o kernel/calc.o kernel/yosys.o OBJS += kernel/driver.o kernel/register.o kernel/rtlil.o kernel/log.o kernel/calc.o kernel/yosys.o
OBJS += kernel/binding.o OBJS += kernel/binding.o
OBJS += kernel/cellaigs.o kernel/celledges.o kernel/satgen.o kernel/scopeinfo.o kernel/qcsat.o kernel/mem.o kernel/ffmerge.o kernel/ff.o kernel/yw.o kernel/json.o kernel/fmt.o OBJS += kernel/cellaigs.o kernel/celledges.o kernel/satgen.o kernel/scopeinfo.o kernel/qcsat.o kernel/mem.o kernel/ffmerge.o kernel/ff.o kernel/yw.o kernel/json.o kernel/fmt.o

View file

@ -28,7 +28,7 @@
ln -s ${abc-verifier}/bin/abc $out/bin/yosys-abc ln -s ${abc-verifier}/bin/abc $out/bin/yosys-abc
''; '';
buildPhase = '' buildPhase = ''
make -j$(nproc) ABCEXTERNAL=yosys-abc make -j$(nproc) ABCEXTERNAL=yosys-abc PROFILER=tracy
''; '';
dontStrip = true; dontStrip = true;
meta = with pkgs.lib; { meta = with pkgs.lib; {

View file

@ -314,6 +314,9 @@ void Pass::call(RTLIL::Design *design, std::vector<std::string> args)
size_t orig_sel_stack_pos = design->selection_stack.size(); size_t orig_sel_stack_pos = design->selection_stack.size();
auto state = pass_register[args[0]]->pre_execute(); auto state = pass_register[args[0]]->pre_execute();
ZoneScopedN(pass_name.c_str());
// ZoneText(pass_name.c_str(), pass_name.length());
ZoneColor((uint32_t)(size_t)pass_name.c_str());
pass_register[args[0]]->execute(args, design); pass_register[args[0]]->execute(args, design);
pass_register[args[0]]->post_execute(state); pass_register[args[0]]->post_execute(state);
while (design->selection_stack.size() > orig_sel_stack_pos) while (design->selection_stack.size() > orig_sel_stack_pos)

View file

@ -1087,10 +1087,10 @@ namespace {
void check_expected(bool check_matched_sign = false) void check_expected(bool check_matched_sign = false)
{ {
for (auto &para : cell->parameters) for (auto &&para : cell->parameters)
if (expected_params.count(para.first) == 0) if (expected_params.count(para.first) == 0)
error(__LINE__); error(__LINE__);
for (auto &conn : cell->connections_) for (auto &&conn : cell->connections_)
if (expected_ports.count(conn.first) == 0) if (expected_ports.count(conn.first) == 0)
error(__LINE__); error(__LINE__);
@ -1973,13 +1973,14 @@ void RTLIL::Module::check()
log_assert(it.first == it.second->name); log_assert(it.first == it.second->name);
log_assert(!it.first.empty()); log_assert(!it.first.empty());
log_assert(!it.second->type.empty()); log_assert(!it.second->type.empty());
for (auto &it2 : it.second->connections_) { for (auto &&it2 : it.second->connections_) {
log_assert(!it2.first.empty()); log_assert(!it2.first.empty());
it2.second.check(this); it2.second.check(this);
} }
for (auto &it2 : it.second->attributes) // TODO
log_assert(!it2.first.empty()); // for (auto &&it2 : it.second->attributes)
for (auto &it2 : it.second->parameters) // log_assert(!it2.first.empty());
for (auto &&it2 : it.second->parameters)
log_assert(!it2.first.empty()); log_assert(!it2.first.empty());
InternalOldCellChecker checker(this, it.second); InternalOldCellChecker checker(this, it.second);
checker.check(); checker.check();
@ -3553,6 +3554,9 @@ const RTLIL::Const RTLIL::Cell::getParam(const RTLIL::IdString &paramname) {
if (type == ID($not)) { if (type == ID($not)) {
if (paramname == ID::A_WIDTH) { if (paramname == ID::A_WIDTH) {
// Notice using the trivial default constructor
// This is to reduce code changes later when we replace Const
// with int/bool where possible in internal cell type variants
return RTLIL::Const(not_.a_width); return RTLIL::Const(not_.a_width);
} else if (paramname == ID::Y_WIDTH) { } else if (paramname == ID::Y_WIDTH) {
return RTLIL::Const(not_.y_width); return RTLIL::Const(not_.y_width);
@ -3739,15 +3743,15 @@ void RTLIL::OldCell::sort()
attributes.sort(sort_by_id_str()); attributes.sort(sort_by_id_str());
} }
void RTLIL::OldCell::check() void RTLIL::Cell::check()
{ {
#ifndef NDEBUG #ifndef NDEBUG
InternalOldCellChecker checker(NULL, this); InternalOldCellChecker checker(NULL, this);
checker.check(); checker.check();
#endif #endif
} }
int bigboy() {return sizeof(RTLIL::Cell);}
void RTLIL::OldCell::fixup_parameters(bool set_a_signed, bool set_b_signed) void RTLIL::Cell::fixup_parameters(bool set_a_signed, bool set_b_signed)
{ {
if (!type.begins_with("$") || type.begins_with("$_") || type.begins_with("$paramod") || type.begins_with("$fmcombine") || if (!type.begins_with("$") || type.begins_with("$_") || type.begins_with("$paramod") || type.begins_with("$fmcombine") ||
type.begins_with("$verific$") || type.begins_with("$array:") || type.begins_with("$extern:")) type.begins_with("$verific$") || type.begins_with("$array:") || type.begins_with("$extern:"))

View file

@ -657,6 +657,7 @@ namespace RTLIL
}; };
}; };
// TODO OF GALACTIC PROPORTIONS
struct RTLIL::Const struct RTLIL::Const
{ {
int flags; int flags;
@ -1591,8 +1592,8 @@ public:
const RTLIL::Const &getParam(const RTLIL::IdString &paramname) const; const RTLIL::Const &getParam(const RTLIL::IdString &paramname) const;
void sort(); void sort();
void check(); // void check();
void fixup_parameters(bool set_a_signed = false, bool set_b_signed = false); // void fixup_parameters(bool set_a_signed = false, bool set_b_signed = false);
bool has_keep_attr() const { bool has_keep_attr() const {
return get_bool_attribute(ID::keep) || (module && module->design && module->design->module(type) && return get_bool_attribute(ID::keep) || (module && module->design && module->design->module(type) &&
@ -1613,20 +1614,21 @@ public:
// $not // $not
struct RTLIL::Unary { struct RTLIL::Unary {
RTLIL::SigSpec a; SigSpec a;
RTLIL::SigSpec y; SigSpec y;
int a_width; Const a_width;
int y_width; Const y_width;
bool is_signed; Const is_signed;
std::array<std::pair<RTLIL::IdString, RTLIL::SigSpec>, 2> connections() { std::array<std::pair<IdString, SigSpec&>, 2> connections() {
return {std::make_pair(ID::A, a), std::make_pair(ID::Y, y)}; return {std::make_pair(ID::A, std::ref(a)), std::make_pair(ID::Y, std::ref(y))};
} }
std::array<std::pair<RTLIL::IdString, RTLIL::Const>, 3> parameters() { std::array<std::pair<IdString, Const&>, 3> parameters() {
return {std::make_pair(ID::A_WIDTH, Const(a_width)), std::make_pair(ID::Y_WIDTH, Const(y_width)), std::make_pair(ID::A_SIGNED, Const(y_width))}; return {std::make_pair(ID::A_WIDTH, std::ref(a_width)), std::make_pair(ID::Y_WIDTH, std::ref(y_width)), std::make_pair(ID::A_SIGNED, std::ref(y_width))};
} }
// TODO new interface: inputs // TODO new interface: inputs
}; };
// NewCell
struct RTLIL::Cell struct RTLIL::Cell
{ {
// TODO huh? // TODO huh?
@ -1704,11 +1706,13 @@ public:
bool operator!=(const iterator &other) const { bool operator!=(const iterator &other) const {
return !(*this == other); return !(*this == other);
} }
std::pair<IdString, Const> operator*() { std::pair<IdString, Const&> operator*() {
if (parent->is_legacy()) { if (parent->is_legacy()) {
auto it = parent->legacy->parameters.begin(); auto it = parent->legacy->parameters.begin();
it += position; it += position;
return *it; auto& ref = *it;
auto ret = std::make_pair(ref.first, std::ref(ref.second));
return ret;
} else if (parent->type == ID($pos)) { } else if (parent->type == ID($pos)) {
return parent->pos.parameters()[position]; return parent->pos.parameters()[position];
} else if (parent->type == ID($neg)) { } else if (parent->type == ID($neg)) {
@ -1719,11 +1723,13 @@ public:
throw std::out_of_range("FakeParams.iterator::operator*()"); throw std::out_of_range("FakeParams.iterator::operator*()");
} }
} }
const std::pair<IdString, Const> operator*() const { const std::pair<IdString, Const&> operator*() const {
if (parent->is_legacy()) { if (parent->is_legacy()) {
auto it = parent->legacy->parameters.begin(); auto it = parent->legacy->parameters.begin();
it += position; it += position;
return *it; auto& ref = *it;
auto ret = std::make_pair(ref.first, std::ref(ref.second));
return ret;
} else if (parent->type == ID($pos)) { } else if (parent->type == ID($pos)) {
return parent->pos.parameters()[position]; return parent->pos.parameters()[position];
} else if (parent->type == ID($neg)) { } else if (parent->type == ID($neg)) {
@ -1736,7 +1742,13 @@ public:
} }
}; };
iterator begin() { iterator begin() {
return iterator(parent, 0); return iterator(parent, 0);
}
// Stupid impl, but rarely used, so I don't want to think about it rn
iterator find(IdString name) {
auto it = iterator(parent, 0);
for (; it != end() && (*it).first != name; ++it) {}
return it;
} }
iterator end() { iterator end() {
if (parent->is_legacy()) { if (parent->is_legacy()) {
@ -1756,8 +1768,8 @@ public:
typedef std::input_iterator_tag iterator_category; typedef std::input_iterator_tag iterator_category;
typedef std::pair<IdString, Const> value_type; typedef std::pair<IdString, Const> value_type;
typedef ptrdiff_t difference_type; typedef ptrdiff_t difference_type;
typedef std::pair<IdString, Const>* pointer; typedef std::pair<IdString, Const*> pointer;
typedef std::pair<IdString, Const>& reference; typedef std::pair<IdString, Const&> reference;
Cell* parent; Cell* parent;
int position; int position;
public: public:
@ -1772,11 +1784,13 @@ public:
bool operator!=(const const_iterator &other) const { bool operator!=(const const_iterator &other) const {
return !(*this == other); return !(*this == other);
} }
const std::pair<IdString, Const> operator*() const { const std::pair<IdString, Const&> operator*() const {
if (parent->is_legacy()) { if (parent->is_legacy()) {
auto it = parent->legacy->parameters.begin(); auto it = parent->legacy->parameters.begin();
it += position; it += position;
return *it; auto& ref = *it;
auto ret = std::make_pair(ref.first, std::ref(ref.second));
return ret;
} else if (parent->type == ID($pos)) { } else if (parent->type == ID($pos)) {
return parent->pos.parameters()[position]; return parent->pos.parameters()[position];
} else if (parent->type == ID($neg)) { } else if (parent->type == ID($neg)) {
@ -1810,6 +1824,12 @@ public:
RTLIL::SigSpec at(RTLIL::IdString portname) { RTLIL::SigSpec at(RTLIL::IdString portname) {
return parent->getPort(portname); return parent->getPort(portname);
} }
// Watch out! This is different semantics than what dict has!
// but we rely on RTLIL::Cell always being constructed correctly
// since its layout is fixed as defined by InternalOldCellChecker
RTLIL::SigSpec operator[](RTLIL::IdString portname) {
return parent->getPort(portname);
}
int count(RTLIL::IdString portname) { int count(RTLIL::IdString portname) {
try { try {
parent->getPort(portname); parent->getPort(portname);
@ -1839,8 +1859,8 @@ public:
typedef std::bidirectional_iterator_tag iterator_category; typedef std::bidirectional_iterator_tag iterator_category;
typedef std::pair<IdString, SigSpec> value_type; typedef std::pair<IdString, SigSpec> value_type;
typedef ptrdiff_t difference_type; typedef ptrdiff_t difference_type;
typedef std::pair<IdString, SigSpec>* pointer; typedef std::pair<IdString, SigSpec*> pointer;
typedef std::pair<IdString, SigSpec>& reference; typedef std::pair<IdString, SigSpec&> reference;
Cell* parent; Cell* parent;
int position; int position;
public: public:
@ -1855,11 +1875,13 @@ public:
bool operator!=(const iterator &other) const { bool operator!=(const iterator &other) const {
return !(*this == other); return !(*this == other);
} }
std::pair<IdString, SigSpec> operator*() { std::pair<IdString, SigSpec&> operator*() {
if (parent->is_legacy()) { if (parent->is_legacy()) {
auto it = parent->legacy->connections_.begin(); auto it = parent->legacy->connections_.begin();
it += position; it += position;
return *it; auto& ref = *it;
auto ret = std::make_pair(ref.first, std::ref(ref.second));
return ret;
} else if (parent->type == ID($pos)) { } else if (parent->type == ID($pos)) {
// auto a = (); // auto a = ();
return parent->pos.connections()[position]; return parent->pos.connections()[position];
@ -1871,11 +1893,13 @@ public:
throw std::out_of_range("FakeConns.iterator::operator*()"); throw std::out_of_range("FakeConns.iterator::operator*()");
} }
} }
const std::pair<IdString, SigSpec> operator*() const { const std::pair<IdString, SigSpec&> operator*() const {
if (parent->is_legacy()) { if (parent->is_legacy()) {
auto it = parent->legacy->connections_.begin(); auto it = parent->legacy->connections_.begin();
it += position; it += position;
return *it; auto& ref = *it;
auto ret = std::make_pair(ref.first, std::ref(ref.second));
return ret;
} else if (parent->type == ID($pos)) { } else if (parent->type == ID($pos)) {
// auto a = (); // auto a = ();
return parent->pos.connections()[position]; return parent->pos.connections()[position];
@ -1909,8 +1933,8 @@ public:
typedef std::input_iterator_tag iterator_category; typedef std::input_iterator_tag iterator_category;
typedef std::pair<IdString, SigSpec> value_type; typedef std::pair<IdString, SigSpec> value_type;
typedef ptrdiff_t difference_type; typedef ptrdiff_t difference_type;
typedef std::pair<IdString, SigSpec>* pointer; typedef std::pair<IdString, SigSpec*> pointer;
typedef std::pair<IdString, SigSpec>& reference; typedef std::pair<IdString, SigSpec&> reference;
Cell* parent; Cell* parent;
int position; int position;
public: public:
@ -1925,11 +1949,13 @@ public:
bool operator!=(const const_iterator &other) const { bool operator!=(const const_iterator &other) const {
return !(*this == other); return !(*this == other);
} }
const std::pair<IdString, SigSpec> operator*() const { const std::pair<IdString, SigSpec&> operator*() const {
if (parent->is_legacy()) { if (parent->is_legacy()) {
auto it = parent->legacy->connections_.begin(); auto it = parent->legacy->connections_.begin();
it += position; it += position;
return *it; auto& ref = *it;
auto ret = std::make_pair(ref.first, std::ref(ref.second));
return ret;
} else if (parent->type == ID($pos)) { } else if (parent->type == ID($pos)) {
return parent->pos.connections()[position]; return parent->pos.connections()[position];
} else if (parent->type == ID($neg)) { } else if (parent->type == ID($neg)) {
@ -1982,17 +2008,24 @@ public:
} }
template<typename T> template<typename T>
void rewrite_sigspecs2(T &functor) { void rewrite_sigspecs2(T &functor) {
for (auto &it : connections_) // for(auto it = connections_.begin(); it != connections_.end(); ++it) {
// auto& thing = *it;
// functor(it.second);
// }
// TODO fix!!!
for (auto &&it : connections_)
functor(it.second); functor(it.second);
} }
template<typename T> template<typename T>
void rewrite_sigspecs(T &functor) { void rewrite_sigspecs(T &functor) {
for (std::pair<IdString, SigSpec> &it : connections_) for (auto &&it : connections_)
functor(it.second); functor(it.second);
} }
void sort() { void sort() {
if (is_legacy()) legacy->sort(); if (is_legacy()) legacy->sort();
} }
void check();
void fixup_parameters(bool set_a_signed = false, bool set_b_signed = false);
private: private: