Skip to content

Commit

Permalink
I am ashamed of this, but stuff has to work soon; I really hope we cl…
Browse files Browse the repository at this point in the history
…ean this up later
  • Loading branch information
SJulianS committed Jul 16, 2024
1 parent 79147a9 commit c9ff3c4
Show file tree
Hide file tree
Showing 6 changed files with 238 additions and 222 deletions.
2 changes: 1 addition & 1 deletion plugins/netlist_preprocessing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ if(PL_NETLIST_PREPROCESSING OR BUILD_ALL_PLUGINS)
SHARED
HEADER ${NETLIST_PREPROCESSING_INC}
SOURCES ${NETLIST_PREPROCESSING_SRC} ${NETLIST_PREPROCESSING_PYTHON_SRC}
LINK_LIBRARIES PUBLIC ${Z3_LIBRARIES} z3_utils OpenMP::OpenMP_CXX
PYDOC SPHINX_DOC_INDEX_FILE ${CMAKE_CURRENT_SOURCE_DIR}/documentation/netlist_preprocessing.rst
LINK_LIBRARIES PUBLIC ${Z3_LIBRARIES} z3_utils resynthesis OpenMP::OpenMP_CXX nlohmann_json::nlohmann_json
)

add_subdirectory(test)
Expand Down
8 changes: 5 additions & 3 deletions plugins/netlist_preprocessing/src/netlist_preprocessing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
#include "hal_core/netlist/net.h"
#include "hal_core/netlist/netlist.h"
#include "hal_core/utilities/token_stream.h"
#include "nlohmann_json/json.hpp"
#include "rapidjson/document.h"
#include "z3_utils.h"
#include "resynthesis/resynthesis.h"
#include "z3_utils/netlist_comparison.h"

#include <fstream>
#include <queue>
Expand Down Expand Up @@ -1347,7 +1349,7 @@ namespace hal
bfs.insert({ep->get_pin()->get_name(), std::move(bf)});
}

auto resynth_res = generate_resynth_netlist_for_boolean_functions(bfs, genlib_path, mux_inv_gl, true);
auto resynth_res = resynthesis::generate_resynth_netlist_for_boolean_functions(bfs, genlib_path, mux_inv_gl, true);
if (resynth_res.is_error())
{
return ERR_APPEND(resynth_res.get_error(), "unable to unify select signals of muxes: failed to resynthesize mux subgraph to netlist");
Expand Down Expand Up @@ -1383,7 +1385,7 @@ namespace hal
global_io_mapping[pin->get_net()].push_back(net);
}

auto replace_res = replace_subgraph_with_netlist(subgraph, global_io_mapping, resynth_nl, nl, false);
auto replace_res = resynthesis::replace_subgraph_with_netlist(subgraph, global_io_mapping, resynth_nl, nl, false);
if (replace_res.is_error())
{
return ERR("unable to unify muxes select signals: failed to replace mux subgraph with resynthesized netlist");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace hal
std::set<std::string> NetlistPreprocessingPlugin::get_dependencies() const
{
std::set<std::string> retval;
// retval.insert("graph_algorithm");
retval.insert("resynthesis");
return retval;
}
} // namespace hal
16 changes: 8 additions & 8 deletions plugins/netlist_preprocessing/test/netlist_preprocessing.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "netlist_preprocessing/plugin_netlist_preprocessing.h"
#include "netlist_preprocessing/netlist_preprocessing.h"

#include "netlist_test_utils.h"
#include "gate_library_test_utils.h"
Expand Down Expand Up @@ -70,7 +70,7 @@ namespace hal {
EXPECT_EQ(l5->get_predecessor("I2")->get_gate(), l2);
EXPECT_EQ(l5->get_predecessor("I3")->get_gate(), l3);

auto res = NetlistPreprocessingPlugin::remove_unused_lut_inputs(nl.get());
auto res = netlist_preprocessing::remove_unused_lut_inputs(nl.get());
ASSERT_TRUE(res.is_ok());
EXPECT_EQ(res.get(), 3);

Expand Down Expand Up @@ -129,7 +129,7 @@ namespace hal {
Net* n3 = test_utils::connect(nl.get(), g0, "O", g1, "I");
Net* n4 = test_utils::connect(nl.get(), g1, "O", g2, "I0");

auto res = NetlistPreprocessingPlugin::remove_buffers(nl.get());
auto res = netlist_preprocessing::remove_buffers(nl.get());
ASSERT_TRUE(res.is_ok());
EXPECT_EQ(res.get(), 1);

Expand Down Expand Up @@ -175,7 +175,7 @@ namespace hal {
Net* n3 = test_utils::connect(nl.get(), g0, "O", g1, "I1");
Net* n4 = test_utils::connect(nl.get(), g1, "O", g2, "I0");

auto res = NetlistPreprocessingPlugin::remove_buffers(nl.get());
auto res = netlist_preprocessing::remove_buffers(nl.get());
ASSERT_TRUE(res.is_ok());
EXPECT_EQ(res.get(), 1);

Expand Down Expand Up @@ -220,7 +220,7 @@ namespace hal {
Net* n3 = test_utils::connect(nl.get(), g0, "O", g1, "I1");
Net* n4 = test_utils::connect(nl.get(), g1, "O", g2, "I0");

auto res = NetlistPreprocessingPlugin::remove_buffers(nl.get());
auto res = netlist_preprocessing::remove_buffers(nl.get());
ASSERT_TRUE(res.is_ok());
EXPECT_EQ(res.get(), 1);

Expand All @@ -236,9 +236,9 @@ namespace hal {
/**
* Test the deletion of redundant logic gates.
*
* Functions: remove_redundant_logic
* Functions: remove_redundant_gates
*/
TEST_F(NetlistPreprocessingTest, check_remove_redundant_logic)
TEST_F(NetlistPreprocessingTest, check_remove_redundant_gates)
{
TEST_START
{
Expand Down Expand Up @@ -274,7 +274,7 @@ namespace hal {
Net* n5 = test_utils::connect(nl.get(), g2, "Q", g4, "I0");
Net* n6 = test_utils::connect(nl.get(), g3, "QN", g4, "I1");

auto res = NetlistPreprocessingPlugin::remove_redundant_logic(nl.get());
auto res = netlist_preprocessing::remove_redundant_gates(nl.get());
ASSERT_TRUE(res.is_ok());
EXPECT_EQ(res.get(), 2);

Expand Down
14 changes: 14 additions & 0 deletions plugins/resynthesis/include/resynthesis/resynthesis.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@
#pragma once

#include "hal_core/defines.h"
#include "hal_core/netlist/boolean_function.h"
#include "hal_core/utilities/result.h"

namespace hal
{
class Netlist;
class Gate;
class Net;
class GateType;
class GateLibrary;

Expand Down Expand Up @@ -147,5 +149,17 @@ namespace hal
* @return OK() and the number of re-synthesized gates on success, an error otherwise.
*/
Result<u32> resynthesize_subgraph_of_type(Netlist* nl, const std::vector<const GateType*>& gate_types, GateLibrary* target_gl);

// TODO functions below wil be removed/replaced soon
Result<std::monostate> replace_subgraph_with_netlist(const std::vector<Gate*>& subgraph,
const std::unordered_map<Net*, std::vector<Net*>>& global_io_mapping,
const Netlist* src_nl,
Netlist* dst_nl,
const bool delete_subgraph_gates);

Result<std::unique_ptr<Netlist>> generate_resynth_netlist_for_boolean_functions(const std::unordered_map<std::string, BooleanFunction>& bfs,
const std::filesystem::path& genlib_path,
GateLibrary* target_gl,
const bool optimize_area);
} // namespace resynthesis
} // namespace hal
Loading

0 comments on commit c9ff3c4

Please sign in to comment.