Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redo internal cell memory layout #4461

Closed
wants to merge 39 commits into from
Closed
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
0fb3f3a
tracy: init, zones per pass execute method, pointer-colored
widlarizer May 28, 2024
60bf00e
tracy: frame pointer, track memory allocations
widlarizer May 31, 2024
b85062f
fix stuff, don't strip
widlarizer Jun 5, 2024
277c10e
oldcell
widlarizer Jun 10, 2024
e243968
delete conn iter attempt
widlarizer Jun 10, 2024
8403eee
iterators
widlarizer Jun 10, 2024
2213b5d
add functions to new cell
widlarizer Jun 10, 2024
930a9f6
add functions to new cell
widlarizer Jun 10, 2024
c0a51c8
wip
widlarizer Jun 10, 2024
d7251df
wip
widlarizer Jun 10, 2024
33910bc
iterator hell
widlarizer Jun 12, 2024
1c2fb07
iterator hell
widlarizer Jun 12, 2024
919e210
references - breaking
widlarizer Jun 12, 2024
33987d9
dead end, backtracking
widlarizer Jun 12, 2024
2d6c454
clean, not backtracking
widlarizer Jun 12, 2024
36289ab
consty stuff
widlarizer Jun 13, 2024
8bdcc69
consty stuff
widlarizer Jun 13, 2024
61cf4b6
look at all those chickens
widlarizer Jun 13, 2024
cc10ef7
silly compat file
widlarizer Jun 13, 2024
193a43e
erase, clear, fork replace, idk
widlarizer Jun 13, 2024
866b7a7
conns and params from dict, oldcell no longer attrobject
widlarizer Jun 13, 2024
4c9f682
tiny fix
widlarizer Jun 13, 2024
eeb15ea
73%
widlarizer Jun 13, 2024
65d50db
100%
widlarizer Jun 14, 2024
fbdfff1
placement new, fix empty probably
widlarizer Jun 17, 2024
43d8c7f
experimenting with test_cell
widlarizer Jun 17, 2024
b190055
fix swapped conns, params in interators
widlarizer Jun 18, 2024
81f783b
cells can now be created, techmap broken
widlarizer Jun 18, 2024
76102f0
$not now passes test_cell!
widlarizer Jun 19, 2024
d2107a9
reconsidering unset
widlarizer Jun 20, 2024
1be8f80
add morphCell instead of type assignments, test_cell passes for all c…
widlarizer Jun 20, 2024
66c6293
fix proc, reduce warnings
widlarizer Jun 21, 2024
343bc66
rtlil: rename InternalOldCellChecker back to InternalCellChecker
widlarizer Jul 10, 2024
6ab2e77
shim: init
widlarizer Jul 11, 2024
b13d092
shim: fix
widlarizer Jul 11, 2024
d04d810
rtlil: fix erase
widlarizer Jul 11, 2024
5ca78ae
mem: fix morphCell calls
widlarizer Jul 11, 2024
6922a68
shim: fix, add forgotten generator
widlarizer Jul 11, 2024
d3d5738
hierarchy: morphCell
widlarizer Jul 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "abc"]
path = abc
url = https://github.com/YosysHQ/abc
[submodule "tracy"]
path = tracy
url = git@github.com:wolfpld/tracy.git
22 changes: 17 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ DISABLE_SPAWN := 0
DISABLE_ABC_THREADS := 0

# clang sanitizers
SANITIZER =
# SANITIZER =
# SANITIZER = address
# SANITIZER = memory
# SANITIZER = undefined
SANITIZER = undefined
# SANITIZER = cfi

PROGRAM_PREFIX :=
Expand Down Expand Up @@ -90,8 +90,8 @@ all: top-all
YOSYS_SRC := $(dir $(firstword $(MAKEFILE_LIST)))
VPATH := $(YOSYS_SRC)

CXXSTD ?= c++11
CXXFLAGS := $(CXXFLAGS) -Wall -Wextra -ggdb -I. -I"$(YOSYS_SRC)" -MD -MP -D_YOSYS_ -fPIC -I$(PREFIX)/include
CXXSTD ?= c++17
CXXFLAGS := $(CXXFLAGS) -Wall -Wextra -ggdb -I. -Itracy/public -I"$(YOSYS_SRC)" -MD -MP -D_YOSYS_ -fPIC -I$(PREFIX)/include
LIBS := $(LIBS) -lstdc++ -lm
PLUGIN_LINKFLAGS :=
PLUGIN_LIBS :=
Expand Down Expand Up @@ -227,6 +227,15 @@ LINKFLAGS += -flto
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)
CXX = g++
CXXFLAGS += -std=$(CXXSTD) -Os
Expand Down Expand Up @@ -557,6 +566,7 @@ $(eval $(call add_include_file,kernel/celledges.h))
$(eval $(call add_include_file,kernel/celltypes.h))
$(eval $(call add_include_file,kernel/consteval.h))
$(eval $(call add_include_file,kernel/constids.inc))
$(eval $(call add_include_file,kernel/compat.h))
$(eval $(call add_include_file,kernel/cost.h))
$(eval $(call add_include_file,kernel/ff.h))
$(eval $(call add_include_file,kernel/ffinit.h))
Expand Down Expand Up @@ -595,7 +605,9 @@ $(eval $(call add_include_file,frontends/ast/ast_binding.h))
$(eval $(call add_include_file,frontends/blif/blifparse.h))
$(eval $(call add_include_file,backends/rtlil/rtlil_backend.h))

OBJS += kernel/driver.o kernel/register.o kernel/rtlil.o kernel/log.o kernel/calc.o kernel/yosys.o
# See -DTRACY_ENABLE
OBJS += tracy/public/TracyClient.o
OBJS += kernel/driver.o kernel/register.o kernel/rtlil.o kernel/log.o kernel/calc.o kernel/yosys.o kernel/compat.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
ifeq ($(ENABLE_ZLIB),1)
Expand Down
5 changes: 3 additions & 2 deletions backends/blif/blif.cc
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,10 @@ struct BlifDumper
return "subckt";
}

void dump_params(const char *command, dict<IdString, Const> &params)
template <typename SmellsLikeDict>
void dump_params(const char *command, SmellsLikeDict &params)
{
for (auto &param : params) {
for (auto param : params) {
f << stringf("%s %s ", command, log_id(param.first));
if (param.second.flags & RTLIL::CONST_FLAG_STRING) {
std::string str = param.second.decode_string();
Expand Down
3 changes: 2 additions & 1 deletion backends/cxxrtl/cxxrtl_backend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2326,7 +2326,8 @@ struct CxxrtlWorker {
f << escape_c_string(data);
}

void dump_metadata_map(const dict<RTLIL::IdString, RTLIL::Const> &metadata_map) {
template <typename SmellsLikeDict>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-1 on this cutesy naming. The "project nyan" stuff (wasn't it NGY?) got old quite a while ago and given how annoying it is to work with Yosys internals the names just make it worse on top.

Copy link
Collaborator Author

@widlarizer widlarizer Jun 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, it's very temporary and should be considered a placeholder for actually using the correct types or just something more terse / clear etc

void dump_metadata_map(const SmellsLikeDict &metadata_map) {
if (metadata_map.empty()) {
f << "metadata_map()";
} else {
Expand Down
2 changes: 1 addition & 1 deletion backends/edif/edif.cc
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ struct EdifBackend : public Backend {
*f << stringf(" (instance %s\n", EDIF_DEF(cell->name));
*f << stringf(" (viewRef VIEW_NETLIST (cellRef %s%s))", EDIF_REF(cell->type),
lib_cell_ports.count(cell->type) > 0 ? " (libraryRef LIB)" : "");
for (auto &p : cell->parameters)
for (auto p : cell->parameters)
add_prop(p.first, p.second);
if (attr_properties)
for (auto &p : cell->attributes)
Expand Down
18 changes: 9 additions & 9 deletions backends/firrtl/firrtl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -480,32 +480,32 @@ struct FirrtlWorker
wire_exprs.push_back(stringf("%s" "inst %s%s of %s %s", indent.c_str(), cell_name.c_str(), cell_name_comment.c_str(), instanceName.c_str(), cellFileinfo.c_str()));

for (auto it = cell->connections().begin(); it != cell->connections().end(); ++it) {
if (it->second.size() > 0) {
const SigSpec &secondSig = it->second;
const std::string firstName = cell_name + "." + make_id(it->first);
if ((*it).second.size() > 0) {
const SigSpec &secondSig = (*it).second;
const std::string firstName = cell_name + "." + make_id((*it).first);
const std::string secondExpr = make_expr(secondSig);
// Find the direction for this port.
FDirection dir = getPortFDirection(it->first, instModule);
FDirection dir = getPortFDirection((*it).first, instModule);
std::string sourceExpr, sinkExpr;
const SigSpec *sinkSig = nullptr;
switch (dir) {
case FD_INOUT:
log_warning("Instance port connection %s.%s is INOUT; treating as OUT\n", cell_type.c_str(), log_signal(it->second));
log_warning("Instance port connection %s.%s is INOUT; treating as OUT\n", cell_type.c_str(), log_signal((*it).second));
YS_FALLTHROUGH
case FD_OUT:
sourceExpr = firstName;
sinkExpr = secondExpr;
sinkSig = &secondSig;
break;
case FD_NODIRECTION:
log_warning("Instance port connection %s.%s is NODIRECTION; treating as IN\n", cell_type.c_str(), log_signal(it->second));
log_warning("Instance port connection %s.%s is NODIRECTION; treating as IN\n", cell_type.c_str(), log_signal((*it).second));
YS_FALLTHROUGH
case FD_IN:
sourceExpr = secondExpr;
sinkExpr = firstName;
break;
default:
log_error("Instance port %s.%s unrecognized connection direction 0x%x !\n", cell_type.c_str(), log_signal(it->second), dir);
log_error("Instance port %s.%s unrecognized connection direction 0x%x !\n", cell_type.c_str(), log_signal((*it).second), dir);
break;
}
// Check for subfield assignment.
Expand Down Expand Up @@ -849,7 +849,7 @@ struct FirrtlWorker
}

auto it = cell->parameters.find(ID::B_SIGNED);
if (it == cell->parameters.end() || !it->second.as_bool()) {
if (it == cell->parameters.end() || !(*it).second.as_bool()) {
b_expr = "asUInt(" + b_expr + ")";
}

Expand Down Expand Up @@ -881,7 +881,7 @@ struct FirrtlWorker
if (cell->type.in(ID($mux), ID($_MUX_)))
{
auto it = cell->parameters.find(ID::WIDTH);
int width = it == cell->parameters.end()? 1 : it->second.as_int();
int width = it == cell->parameters.end()? 1 : (*it).second.as_int();
string a_expr = make_expr(cell->getPort(ID::A));
string b_expr = make_expr(cell->getPort(ID::B));
string s_expr = make_expr(cell->getPort(ID::S));
Expand Down
2 changes: 1 addition & 1 deletion backends/intersynth/intersynth.cc
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ struct IntersynthBackend : public Backend {
node_code += stringf(" %s %s", log_id(port.first), netname(conntypes_code, celltypes_code, constcells_code, sig).c_str());
}
}
for (auto &param : cell->parameters) {
for (auto param : cell->parameters) {
celltype_code += stringf(" cfg:%d %s", int(param.second.bits.size()), log_id(param.first));
if (param.second.bits.size() != 32) {
node_code += stringf(" %s '", log_id(param.first));
Expand Down
5 changes: 3 additions & 2 deletions backends/jny/jny.cc
Original file line number Diff line number Diff line change
Expand Up @@ -342,11 +342,12 @@ struct JnyWriter
}
}

void write_prams(dict<RTLIL::IdString, RTLIL::Const>& params, uint16_t indent_level = 0) {
template <typename SmellsLikeDict>
void write_prams(SmellsLikeDict& params, uint16_t indent_level = 0) {
const auto _indent = gen_indent(indent_level);

bool first_param{true};
for (auto& param : params) {
for (auto param : params) {
if (!first_param)
f << stringf(",\n");
const auto param_val = param.second;
Expand Down
6 changes: 3 additions & 3 deletions backends/json/json.cc
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,11 @@ struct JsonWriter
f << get_string(value.as_string());
}
}

void write_parameters(const dict<IdString, Const> &parameters, bool for_module=false)
template <typename SmellsLikeDict>
void write_parameters(const SmellsLikeDict &parameters, bool for_module=false)
{
bool first = true;
for (auto &param : parameters) {
for (auto param : parameters) {
f << stringf("%s\n", first ? "" : ",");
f << stringf(" %s%s: ", for_module ? "" : " ", get_name(param.first).c_str());
write_parameter_value(param.second);
Expand Down
2 changes: 1 addition & 1 deletion backends/rtlil/rtlil_backend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ void RTLIL_BACKEND::dump_cell(std::ostream &f, std::string indent, const RTLIL::
f << stringf("\n");
}
f << stringf("%s" "cell %s %s\n", indent.c_str(), cell->type.c_str(), cell->name.c_str());
for (auto &it : cell->parameters) {
for (auto it : cell->parameters) {
f << stringf("%s parameter%s%s %s ", indent.c_str(),
(it.second.flags & RTLIL::CONST_FLAG_SIGNED) != 0 ? " signed" : "",
(it.second.flags & RTLIL::CONST_FLAG_REAL) != 0 ? " real" : "",
Expand Down
24 changes: 12 additions & 12 deletions backends/verilog/verilog_backend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1895,9 +1895,9 @@ void dump_cell(std::ostream &f, std::string indent, RTLIL::Cell *cell)
for (auto it = cell->parameters.begin(); it != cell->parameters.end(); ++it) {
if (it != cell->parameters.begin())
f << stringf(",");
f << stringf("\n%s .%s(", indent.c_str(), id(it->first).c_str());
if (it->second.size() > 0)
dump_const(f, it->second);
f << stringf("\n%s .%s(", indent.c_str(), id((*it).first).c_str());
if ((*it).second.size() > 0)
dump_const(f, (*it).second);
f << stringf(")");
}
f << stringf("\n%s" ")", indent.c_str());
Expand All @@ -1915,36 +1915,36 @@ void dump_cell(std::ostream &f, std::string indent, RTLIL::Cell *cell)
char str[16];
snprintf(str, 16, "$%d", i);
for (auto it = cell->connections().begin(); it != cell->connections().end(); ++it) {
if (it->first != str)
if ((*it).first != str)
continue;
if (!first_arg)
f << stringf(",");
first_arg = false;
f << stringf("\n%s ", indent.c_str());
dump_sigspec(f, it->second);
numbered_ports.insert(it->first);
dump_sigspec(f, (*it).second);
numbered_ports.insert((*it).first);
goto found_numbered_port;
}
break;
found_numbered_port:;
}
for (auto it = cell->connections().begin(); it != cell->connections().end(); ++it) {
if (numbered_ports.count(it->first))
if (numbered_ports.count((*it).first))
continue;
if (!first_arg)
f << stringf(",");
first_arg = false;
f << stringf("\n%s .%s(", indent.c_str(), id(it->first).c_str());
if (it->second.size() > 0)
dump_sigspec(f, it->second);
f << stringf("\n%s .%s(", indent.c_str(), id((*it).first).c_str());
if ((*it).second.size() > 0)
dump_sigspec(f, (*it).second);
f << stringf(")");
}
f << stringf("\n%s" ");\n", indent.c_str());

if (defparam && cell->parameters.size() > 0) {
for (auto it = cell->parameters.begin(); it != cell->parameters.end(); ++it) {
f << stringf("%sdefparam %s.%s = ", indent.c_str(), cell_name.c_str(), id(it->first).c_str());
dump_const(f, it->second);
f << stringf("%sdefparam %s.%s = ", indent.c_str(), cell_name.c_str(), id((*it).first).c_str());
dump_const(f, (*it).second);
f << stringf(";\n");
}
}
Expand Down
11 changes: 6 additions & 5 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,22 @@
# TODO: don't override src when ./abc is empty
# which happens when the command used is `nix build` and not `nix build ?submodules=1`
abc-verifier = pkgs.abc-verifier.overrideAttrs(x: y: {src = ./abc;});
yosys = pkgs.clangStdenv.mkDerivation {
yosys = pkgs.llvmPackages.libcxxStdenv.mkDerivation {
name = "yosys";
src = ./. ;
buildInputs = with pkgs; [ clang bison flex libffi tcl readline python3 llvmPackages.libcxxClang zlib git pkg-configUpstream ];
buildInputs = with pkgs; [ bison flex libffi tcl readline python3 llvmPackages.libcxxClang zlib git pkg-configUpstream tracy ];
checkInputs = with pkgs; [ gtest ];
propagatedBuildInputs = [ abc-verifier ];
preConfigure = "make config-clang";
checkTarget = "test";
installPhase = ''
make install PREFIX=$out ABCEXTERNAL=yosys-abc
make install PREFIX=$out ABCEXTERNAL=yosys-abc STRIP=\#
ln -s ${abc-verifier}/bin/abc $out/bin/yosys-abc
'';
buildPhase = ''
make -j$(nproc) ABCEXTERNAL=yosys-abc
make -j$(nproc) ABCEXTERNAL=yosys-abc PROFILER=tracy
'';
dontStrip = true;
meta = with pkgs.lib; {
description = "Yosys Open SYnthesis Suite";
homepage = "https://yosyshq.net/yosys/";
Expand All @@ -41,7 +42,7 @@
packages.default = yosys;
defaultPackage = yosys;
devShell = pkgs.mkShell {
buildInputs = with pkgs; [ clang bison flex libffi tcl readline python3 llvmPackages.libcxxClang zlib git gtest abc-verifier ];
buildInputs = with pkgs; [ clang bison flex libffi tcl readline python3 llvmPackages.libcxxClang zlib git gtest abc-verifier tracy ];
};
}
);
Expand Down
6 changes: 4 additions & 2 deletions frontends/aiger/aigerparse.cc
Original file line number Diff line number Diff line change
Expand Up @@ -766,15 +766,17 @@ void AigerReader::post_process()
{
unsigned ci_count = 0, co_count = 0;
for (auto cell : boxes) {
for (auto &bit : cell->connections_.at(ID(i))) {
auto sig_inp = cell->connections_.at(ID(i));
for (auto &bit : sig_inp) {
log_assert(bit == State::S0);
log_assert(co_count < outputs.size());
bit = outputs[co_count++];
log_assert(bit.wire && GetSize(bit.wire) == 1);
log_assert(bit.wire->port_output);
bit.wire->port_output = false;
}
for (auto &bit : cell->connections_.at(ID(o))) {
auto sig_outp = cell->connections_.at(ID(i));
for (auto &bit : sig_outp) {
log_assert(bit == State::S0);
log_assert((piNum + ci_count) < inputs.size());
bit = inputs[piNum + ci_count++];
Expand Down
2 changes: 1 addition & 1 deletion frontends/blif/blifparse.cc
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ void parse_blif(RTLIL::Design *design, std::istream &f, IdString dff_name, bool
};

dict<RTLIL::IdString, RTLIL::Const> *obj_attributes = nullptr;
dict<RTLIL::IdString, RTLIL::Const> *obj_parameters = nullptr;
RTLIL::Cell::FakeParams *obj_parameters = nullptr;

dict<RTLIL::IdString, std::pair<int, bool>> wideports_cache;

Expand Down
3 changes: 2 additions & 1 deletion frontends/json/jsonparse.cc
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,8 @@ Const json_parse_attr_param_value(JsonNode *node)
return value;
}

void json_parse_attr_param(dict<IdString, Const> &results, JsonNode *node)
template <typename SmellsLikeDict>
void json_parse_attr_param(SmellsLikeDict &results, JsonNode *node)
{
if (node->type != 'D')
log_error("JSON attributes or parameters node is not a dictionary.\n");
Expand Down
20 changes: 20 additions & 0 deletions kernel/compat.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include "hashlib.h"
#include "rtlil.h"

YOSYS_NAMESPACE_BEGIN

/**
* not sure if I need this file but this couldn't go in either
* hashlib or rtlil without adding an include to the other header
*/

dict<RTLIL::IdString, RTLIL::Const> cell_to_mod_params (const RTLIL::Cell::FakeParams& cell_params) {
dict<RTLIL::IdString, RTLIL::Const> ret;
for (auto i : cell_params){
ret[i.first] = i.second;
}
return ret;

}

YOSYS_NAMESPACE_END
12 changes: 12 additions & 0 deletions kernel/compat.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// TODO header whatever

#ifndef COMPAT_H
#define COMPAT_H

YOSYS_NAMESPACE_BEGIN

dict<RTLIL::IdString, RTLIL::Const> cell_to_mod_params (const RTLIL::Cell::FakeParams& cell_params);

YOSYS_NAMESPACE_END

#endif
2 changes: 1 addition & 1 deletion kernel/ffmerge.cc
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ void FfMergeHelper::set(FfInitVals *initvals_, RTLIL::Module *module_)
for (int i = 0; i < GetSize(q); i++)
dff_driver[q[i]] = std::make_pair(cell, i);
}
for (auto &conn : cell->connections())
for (auto conn : cell->connections_)
if (!cell->known() || cell->input(conn.first))
for (auto bit : (*sigmap)(conn.second))
sigbit_users_count[bit]++;
Expand Down
2 changes: 1 addition & 1 deletion kernel/mem.cc
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ namespace {
res.packed = true;
res.cell = cell;
res.attributes = cell->attributes;
Const &init = cell->parameters.at(ID::INIT);
const Const &init = cell->parameters.at(ID::INIT);
if (!init.is_fully_undef()) {
int pos = 0;
while (pos < res.size) {
Expand Down
2 changes: 2 additions & 0 deletions kernel/register.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#include "kernel/yosys_common.h"
#include "kernel/yosys.h"

#include "tracy/public/tracy/Tracy.hpp"

YOSYS_NAMESPACE_BEGIN

struct Pass
Expand Down
Loading
Loading